터미널에서 아래 실행
$ git config --global user.name <username>
$ git config --global user.email <email>
$ git config --global core.autocrlf input
# 설정 완료된 것 확인하기
git config --list
credential.helper=osxkeychain
init.defaultbranch=main
user.name=<username>
user.email=<email>
core.autocrlf=input
core.editor=vim
# 하나씩 쳐서 확인도 가능
$ git config user.name
1. 실습할 Workspace 생성
% mkdir git_ws
2. Working Directory 생성 및 git init하면 해당 폴더를 Local Repository로서 관리
git init
폴더에서 Git을 초기화하는 명령어를 사용하면 해당 폴더를 Git이 관리하기 시작% cd git_ws
git_ws % mkdir test_project
git_ws % cd test_project
test_project % git init
Initialized empty Git repository in /Users/sy/git_ws/test_project/.git/
(base) sy@Lees-MacBook-Pro test_project % ls -all
total 0
drwxr-xr-x 3 sy staff 96 9 7 14:34 .
drwxr-xr-x 4 sy staff 128 9 7 14:33 ..
drwxr-xr-x 9 sy staff 288 9 7 14:34 .git
(base) sy@Lees-MacBook-Pro test_project % cd .git
(base) sy@Lees-MacBook-Pro .git % ls -all
total 24
drwxr-xr-x 9 sy staff 288 9 7 14:34 .
drwxr-xr-x 3 sy staff 96 9 7 14:34 ..
-rw-r--r-- 1 sy staff 21 9 7 14:34 HEAD
-rw-r--r-- 1 sy staff 137 9 7 14:34 config
-rw-r--r-- 1 sy staff 73 9 7 14:34 description
drwxr-xr-x 15 sy staff 480 9 7 14:34 hooks
drwxr-xr-x 3 sy staff 96 9 7 14:34 info
drwxr-xr-x 4 sy staff 128 9 7 14:34 objects
drwxr-xr-x 4 sy staff 128 9 7 14:34 refs
touch {파일명}
: 비어있는 파일 하나를 생성해주는 명령어(base) sy@Lees-MacBook-Pro test_project % touch test.txt
(base) sy@Lees-MacBook-Pro test_project % ls
test.txt
git status
git에 존재하는 파일 확인 -> 자주 확인하는 습관을 들이기 ⭐️(base) sy@Lees-MacBook-Pro test_project % git status
On branch main # 현재 main branch에 있다
No commits yet # 아직 commit한 건 없다
Untracked files: # working directory에는 있는데 stage에는 존재하지 않는 파일이 있다
(use "git add <file>..." to include in what will be committed)
test.txt
git add <filename>
⭐️(base) sy@Lees-MacBook-Pro test_project % git add test.txt
(base) sy@Lees-MacBook-Pro test_project % git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
git commit -m "commit 변경사항에 대한 설명" <filename>
⭐️⭐️(base) sy@Lees-MacBook-Pro test_project % git commit -m "테스트임" test.txt
[main (root-commit) 4b24e0e] 테스트임
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test.txt
(base) sy@Lees-MacBook-Pro test_project % git status
On branch main
nothing to commit, working tree clean
*참고) Mac에서 command+shit+. 하면 숨김파일 볼 수 있음
git remote add origin https://<username>:<token>@github.com/<repository>.git
<username>:<token>
을 함께 입력해주면 remote repository에 push, pull할 때 username과 token을 물어보지 않고 자동으로 입력해서 편리함.git remote -v
로 remote repository 연결 여부 확인git push origin master
git push origin main
(예전에는 master 썼는데 요즘에는 main으로 바뀜)git pull origin <branchname: main 등>
ls
했을 때, README.md test.txt 로 추가된 것 확인할 수 있음.cat exam.txt
와 같이 입력하면 파일을 읽어옴Local Repository 생성하지 않은 상태에서 git clone 명령으로 Remote Repository을 local에 복제하기
git clone https://<username>:<token>@github.com/<repository>.git
~/git_ws $ git clone https://ssuyeonlee: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@github.com/ssuyeonlee/HelloGit.git
Cloning into 'HelloGit'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (4/4), done.
~/git_ws $ cd HelloGit
~/git_ws/HelloGit $ ls -all
total 16
drwxr-xr-x 5 sy staff 160 9 7 16:33 .
drwxr-xr-x 6 sy staff 192 9 7 16:33 ..
drwxr-xr-x 12 sy staff 384 9 7 16:33 .git
-rw-r--r-- 1 sy staff 3139 9 7 16:33 .gitignore
-rw-r--r-- 1 sy staff 10 9 7 16:33 README.md
git branch
Local에 있는 branch 조회git branch -r
Remote에 있는 branch 조회git branch -a
Local+Remote에 있는 branch 모두 조회q
로 빠져나오기$ git branch -a
* main # *: 현재 위치한 branch가 어디인지 나타냄
remotes/origin/HEAD -> origin/main
remotes/origin/main
git branch <branchname>
git checkout <branchname>
git checkout -b <branchname>
git push origin <branchname>
git branch -d <branchname>
git push origin --delete <branchname>
git graph extension 설치하기
사용 중인 git에서 로그들을 시각화하여 확인할 수 있음.
좌측 3번째 메뉴 클릭 > SOURCE CONTROL 우측 4번째 branch같은 아이콘 클릭
사실 터미널에서 git log
로 해당 git에서 있었던 로그들도 확인 가능 (나갈 때는 q
입력)
git config --global core.editor <editorname> --wait
git config --global -e
[core]
autocrlf = input
editor = code --wait
[diff]
tool = vscode
[difftool "vscode"]
cmd = "code --wait --diff $LOCAL $REMOTE"
git diff <branch1> <branch2>
git difftool <branch1> <branch2>
git difftool <commithash> <commithash>
git log
에서 각 commit별 뒤의 문자열git difftool 2c5a4faa4a9bf99e8cf2cdbc4e7ccbe8d5f40261 374c98f8129ec5a8b2db09b93f611d5eacb6dcd6
실행git difftool HEAD HEAD^
(여기까지 잘 확인하지는 않긴 함)
git difftool HEAD
git diff <branch> origin/<branch2>
origin/<branch2>
: Remote Repository를 의미하는 origin에서의 어떤 branch와 비교할지를 입력하는 부분git config --global -e
실행하여 아래 내용을 최하단에 추가
[merge]
tool = vscode
[mergetool "vscode"]
cmd = "code --wait $MERGED"
git merge <branchname>
$ git merge dev2
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
git mergetool
을 사용하여 해결해보자!git merge dev2
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
git tag <tagname>
: Local에서 마지막 버전(commit)에 tag 달기git tag <tagname> <commithash>
: Local에서 특정 버전(commit)에 tag 달기 -> commit 2에 tag 달림git push origin <tagname>
: Local에서 위와 같이 달았던 Tag를 Remote에도 반영해야 할 때 Tag를 push해줌.git tag
: 현재까지 Local에서 설정한 tag 목록 보기git show <tagname>
: tag의 상세 정보 확인하기git tag --delete <tagname>
: Local의 tag 삭제git push --delete origin <tagname>
: Remote의 tag 삭제 (Remote에서만 삭제하고 Local에서는 삭제하지 않을 때도 이것만 실행하면 됨)cat 파일명
: 파일을 읽어옴
cat > 파일명
: 파일이 존재하면 파일의 내용을 입력하는 값으로 덮어씌움. 파일이 존재하지 않는다면 입력하는 값으로 파일을 생성함. 내용 입력 후 엔터. 모두 다 입력했으면 control+d로 완료하기.
cat >> 파일명
: >>를 쓰면 덮어씌우지 않고 밑줄에 이어서 내용이 추가됨.
code .
현재 위치에서 VSCode 열기