오늘은 형상 관리 주요 툴로 이용되는 Git의 기초 사용법과 원격저장소인 Github와 연결하는 기초적인 사항에 대해서 작성해보려 한다.
$ git init
Initialized empty Git repository in C:/Users/livem/OneDrive/바탕 화면/first/.git/
(master) $
.git
폴더가 생성 => 버전이 기록되는 저장소$ git init
을 하게 되면 (master)
가 생기게 된다.livem@DESKTOP-V69ULCI MINGW64 ~/Desktop/test (master)
내가 조작을 하고자 하는 working directory (working tree)에서 add
명령어를 통해 파일이나 폴더를 Staging Area (Index)로 보내고(?) commit
명령어를 통해 Staging Area에 있는 파일이나 폴더들을 .git 폴더로 보내고 이 폴더에서 버전별로 파일이나 폴더들을 관리하는 거라고 생각하면 된다. 이후 push
또는 pull
명령어를 통해 원격저장소 (git hub)와 연결된다.
Add file contents to the index
$ git add 파일명
$ git add a.txt
$ git add my_folder/
$ git add a.txt b.txt
add 취소하기
$ git restore --staged 파일명
Record changes to the repository
$ git commit -m "커밋메세지"
commit 메세지 변경, 주의해서 사용!
$ git commit --amend
커밋 메시지는 항상 버전의 내용(변경사항)에 대해서 나타낼 수 있도록 기록한다.
a.txt 수정이 완료되어서 add를 하면 파일이 staging area로 이동하고 commit을 하면 repository (.git 폴더)로 이동하게 된다.
각 commit은 고유한 값을 가지고 있고, 다른 경우 다른 commit이다.
$ git remote -v
origin https://github.com/letgodchan0/first.git (fetch)
origin https://github.com/letgodchan0/first.git (push)
$ git remote add <원격저장소이름> <url>
$ git remote add origin https://github.com/username/repository.git
origin
: 일반적으로 많이 활용되는 원격저장소 이름$ git remote rm <원격저장소이름>
$ git remote rm origin
Update remote refs along with associated objects
$ git push <원격저장소이름> <브랜치이름>
$ git push origin master
.git
폴더에 있는 최신 버전의 파일들을 원격저장소에서 저장(?)하기 위한 명령어Fetch from and integrate with another repository or a local
$ git pull <원격저장소 이름> <브랜치 이름>
$ git pull origin master
Clone a repository into a new directory
$ git clone <원격저장소 주소>
$ git clone https://github.com/username/repository.git
파일의 add 상태를 확인해 볼 수 있는 명령어
$ git status
# 일반적으로 아무것도 하지 않았을 때 상태 (모든 버전이 커밋이 완료된 상태)ㅎ
On branch main
nothing to commit, working tree clean
# 커밋 할 변경사항들 (Staging area에 있어)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: b.txt
# 커밋을 위해 준비되지 않은 변경사항 (Staging area에 없고 Working directory에 있어)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a.txt
# 트래킹되지 않은 파일들 (Working directory, 생에 처음으로 commit되길 기다리고 있음)
Untracked files:
(use "git add <file>..." to include in what will be committed)
c.txt
$ git log
commit b117d36373787c806f528d01ec76450f65a1aed4 (HEAD -> master)
Author: letgodchan0 <letgodchan0@gmail.com>
Date: Thu Jan 13 12:29:28 2022 +0900
Initial commit
로그에서 출력되는 버전 간의 차이점을 출력하고 싶을 때
$ git log -p
$ git restore --staged 파일명
# a.txt 파일이 생성된다
touch a.txt
git pull origin master'
명령어를 통해 원격저장소에서의 최신 버전을 로컬에 적용시켜주어야 할 필요가 있다.$ git init # 해당 폴더를 깃으로 관리하겠다
git config --global user.email "여러분들의 이메일"
git config --global user.name "영어id"
$ git status # 해당 폴더의 git의 관리 상태를 보겠다.
$ touch README.md # 해당 폴더에 README 파일 만들기
$ git add README.MD # README 파일을 git 관리에 추가하겠다.
$ git commit -m "원하는 커밋 메세지" # add한 파일들의 버전을 로컬에서 관리하겠다.
$ git remote add origin 원격자정소 주소 # 원격저장소와 해당 폴더를 연결하겠다.
$ git push origin master # master branch에 push 하겠다. (원격저장소에 저장하겠다.)
$ git pull origin master # 원격저장소에서 커밋한 내용을 로컬에 반영하겠다
오류가 있으면 댓글 달아주세요🙂