Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

미국 사는 수스의 코딩

Git 명령어 정리 | 예시 본문

Git

Git 명령어 정리 | 예시

캘리 사는 수스 2023. 3. 1. 19:11
반응형

Git Command 명령어

git init <directory>: Git repository를 directory에 초기화

git add <file>: 수정된 소스 코드를 Staging Area로 추가

git commit -m "any message": Staging Area에 추가된 소스 코드들을 Local Repository에 추가 (메세지 추가할 수 있다)

git push : Local Repository에서 변경된 파일들을 Remote Repository에 넣음

git pull : Remote Repository에 모든 변경된 파일들을 내 local Repository에 끌고 옴

git clone <url>: 현재 있는 directory에 url로 명시되어있는 Repository의 복사본을 저장

 

git status : working directory와 staging area 안에 있는 파일들의 상태들을 확인

git checkout :

  • git checkout <branch> : 다른 branch로 이동
  • git checkout -b <new-branch> : new-branch 생성 후 그 새로운 branch로 이동

git branch : 현재있는 repository에 모든 branch를 보여줌

  • git branch <new-branch> : new-branch 생성
  • git branch -d <branch> : branch 삭제 (merge된 branch만 가능)
  • git branch -D <branch> : branch 상태와 상관없이 삭제

git remote : github remote repo의 URL을 관리하는 command

  • git remote add [alias] url : url을 alias로 관리하며, remote repository를 명시

git merge <branch> : 지정한 branch를 현재 있는 branch에 병합

git rebase <branch> : 지정한 branch에 현재 있는 branch를 재배치

 

google에서 git cheat sheet이라고 검색하면 더 많은 command가 나옵니다.

https://about.gitlab.com/images/press/git-cheat-sheet.pdf

 


Git Command 예시

예시를 보여주기에 앞서, Github을 셋업하는 방법을 설명합니다.

Github setup

1. Github account을 만들고 "Repositories" 창으로 들어가서 "New" 클릭 (여기서 생성되는 Repo는 Remote Repo입니다)

2.Github에서 만든 repository에 들어가서 HTTPS를 다운로드합니다.

3. Token 생성 : 맨 처음 github environment을 PC에 셋업하실때 github repository에 들어갈 수 있도록 토큰을 생성합니다.

https://github.com/settings/tokens/new

 

3.git clone 카피한 url 안에 token을 넣고 마지막 ".git"는 지워줍니다. (https://[TOKEN]@github.com/repo_owner/repo_name)

4.git init

5. git checkout -b test_branch (branch 생성 후 이동)

6. git status

7.아무런 파일을 생성하시고 git status를 하면 untracked files에 파일이 있다는 걸 확인할 수 있습니다.

8. git add test.py (만든 파일을 git add하면 staging area에 추가가 됩니다)

9. git commit -m "아무 message" (staging area에 있었던 test.py 파일이 local repository에 세이브가 됩니다)

10. git remote add origin url주소 (github 웹사이트에서 HTTPS 주소)

11. git push origin test_branch (push는 만들었던 branch로 합니다. local repo 안에 있는 test_branch가 remote repo의 test_branch로 push한다는 걸 의미합니다)

12. Github의 repository (remote repository)에 push했던 파일이 업로드된 것을 확인할 수 있습니다.

반응형

'Git' 카테고리의 다른 글

Git 브랜치 병합/재배치 : Git rebase  (0) 2023.03.19
Git 브랜치 병합 : Git merge  (0) 2023.03.15
Git 커밋 취소 : Git revert 되돌리기  (0) 2023.03.15
Git Command 취소 : Git reset  (0) 2023.03.05
Git 용도와 구성 설명  (0) 2023.02.27
Comments