|
1 | 1 | # git 명령어 |
2 | 2 |
|
3 | 3 |
|
| 4 | +## 최초 git 설정 |
| 5 | + |
| 6 | +* https://git-scm.com/ 설치 |
| 7 | +* git bash 열기 |
4 | 8 |
|
5 | | -## 덮어쓰기 |
6 | 9 | ``` |
7 | | -git reset --hard origin |
8 | | -git reset --soft origin |
9 | | -git reset --soft HEAD~{커밋수} |
10 | | -git reset --hard origin/{브랜치-이름} |
| 10 | +git config --global user.name "{사용자-이름}" |
| 11 | +git config --global user.email "{사용자-이메일}" |
| 12 | +git config --list |
11 | 13 | ``` |
| 14 | + |
12 | 15 |
|
13 | 16 |
|
14 | 17 |
|
15 | | -## 커밋합치기 |
| 18 | + |
| 19 | +## 새 저장소 만들기 |
| 20 | + |
16 | 21 | ``` |
17 | | -git rebase -i HEAD~{커밋수} |
| 22 | +echo "# test" >> README.md |
| 23 | +git init |
| 24 | +git add README.md |
| 25 | +git commit -m "first commit" |
| 26 | +git branch -M master |
| 27 | +git remote add origin https://github.com/code1009/{저장소-이름}.git |
| 28 | +git push -u origin master |
| 29 | +``` |
| 30 | + |
| 31 | + |
| 32 | +## 기존 저장소 푸시 |
| 33 | + |
| 34 | +``` |
| 35 | +git remote add origin https://github.com/code1009/{저장소-이름}.git |
| 36 | +git branch -M master |
| 37 | +git push -u origin master |
| 38 | +``` |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | +## 원격 연결 확인 |
| 43 | + |
| 44 | +* 명령어 |
| 45 | +``` |
| 46 | +git remote -v |
| 47 | +``` |
| 48 | + |
| 49 | +* 출력결과 |
| 50 | +``` |
| 51 | +origin https://github.com/code1009/{저장소-이름}.git (fetch) |
| 52 | +origin https://github.com/code1009/{저장소-이름}.git (push) |
| 53 | +``` |
| 54 | + |
| 55 | + |
| 56 | +## 복제(clone) |
| 57 | + |
| 58 | +``` |
| 59 | +git clone {저장소-주소} {로컬-폴더} |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +## 로컬에서 브랜치 생성 및 전환 |
| 65 | + |
| 66 | +``` |
| 67 | +git checkout -b {브랜치-이름} |
| 68 | +``` |
| 69 | +> `-b` 생성 옵션 |
| 70 | +
|
| 71 | + |
| 72 | +## 로컬에서 브랜치 생성 및 전환 후 푸쉬 |
| 73 | + |
| 74 | +``` |
| 75 | +git push --set-upstream origin {브랜치-이름} |
| 76 | +``` |
| 77 | + |
| 78 | +> 최초 푸시 시 필요함 |
| 79 | +
|
| 80 | + |
| 81 | + |
| 82 | +## 원격 동기화 |
| 83 | + |
| 84 | +``` |
| 85 | +git fetch origin |
18 | 86 | ``` |
19 | 87 |
|
20 | 88 |
|
21 | 89 |
|
22 | | -## 로컬에서 브랜치전환 |
| 90 | +## 로컬에서 브랜치 전환 |
| 91 | + |
23 | 92 | ``` |
24 | 93 | git checkout {브랜치-이름} |
25 | 94 | ``` |
26 | 95 |
|
27 | 96 |
|
| 97 | +## 충돌(conflict) 이후 해결 예시 |
| 98 | + |
| 99 | +* develop 브랜치 최신 내용 feature 브랜치에 병합 |
| 100 | + |
| 101 | +``` |
| 102 | +git checkout develop |
| 103 | +git pull origin develop |
| 104 | +git checkout feature |
| 105 | +git merge develop |
| 106 | +``` |
| 107 | + |
| 108 | +* 충돌 해결 후 커밋 및 푸시 |
| 109 | + |
| 110 | +``` |
| 111 | +git add . |
| 112 | +git commit -m "resolve conflicts" |
| 113 | +git push |
| 114 | +``` |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +## 서로 다른 저장소 이력 병합 |
28 | 119 |
|
29 | | -## 새 저장소의 초기 커밋을 기존 저장소와 병합 |
30 | 120 | ``` |
31 | 121 | git pull origin {브랜치-이름} --allow-unrelated-histories |
32 | 122 | ``` |
33 | 123 |
|
34 | 124 |
|
35 | 125 |
|
36 | | -## 저장소의 초기화 |
| 126 | +## 저장소 초기화 |
| 127 | + |
37 | 128 | ``` |
38 | | -{.git 폴더 삭제} |
| 129 | +{.git 폴더 삭제(`rmdir /s /q .git`} |
39 | 130 | git init |
40 | 131 | git add --all |
41 | 132 | git commit -m "init" |
42 | | -git remote add origin https://github.com/code1009/{저장소 이름}.git |
| 133 | +git remote add origin https://github.com/code1009/{저장소-이름}.git |
43 | 134 | git push -f origin master |
44 | 135 | ``` |
45 | 136 |
|
| 137 | + |
| 138 | + |
| 139 | +## 커밋 이력 확인 |
| 140 | + |
| 141 | +``` |
| 142 | +git log |
| 143 | +``` |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | +## 저장소 상태 확인 |
| 148 | + |
| 149 | +``` |
| 150 | +git status |
| 151 | +``` |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +## 덮어쓰기 |
| 156 | + |
| 157 | +``` |
| 158 | +git reset --hard origin |
| 159 | +git reset --soft origin |
| 160 | +git reset --soft HEAD~{커밋수} |
| 161 | +git reset --hard origin/{브랜치-이름} |
| 162 | +``` |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | +## 커밋 합치기 |
| 167 | + |
| 168 | +``` |
| 169 | +git rebase -i HEAD~{커밋수} |
| 170 | +``` |
| 171 | +> 가급적 금지 |
| 172 | +> > 협업 중인 브랜치에서 rebase는 충돌 및 이력 꼬임 위험 |
| 173 | +
|
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
0 commit comments