TIL_020_210223

James·2021년 2월 23일
0

TILs

목록 보기
20/40

자주 쓰는 git 명령어 정리

  1. git clone [URL of repo.] :
    => remote repo.의 파일을 local repo.로 이동
  2. git add [file name] :
    => staging area로 이동 및 변경 전 후 비교 가능
  3. git commit -m "commit name" :
    => staging area에 있는 파일들을 local repo로 이동
  4. git push [repo. name][branch name] :
    => local repo에 있는 파일을 remote repo.로 업로드 하는데, repo. name의 branch name으로 이동
  5. git pull [repo. nickName][branch name] :
    => 다른 유저의 repo.의 파일을 내 local repo.로 가져오고 merge까지 수행
  6. git remote :
    => 현재 내 local repo.와 연결되어 있는 remote repo. name들을 확인
  7. git remote -v :
    => 현재 내 local repo.와 연결되어 있는 remote repo. name과 그에 해당하는 URL까지 함께 확인
  8. git remote add [Nickname][repo.URL] :
    => 타인의 repo.를 내 remote repo.목록에 추가한다. 추가할 때 사용한 Nickname을 이용해서 추후에 git pull [Nickname][branch] 사용할 수 있다.
  9. git checkout [existed branch name] :
    => working branch를 현재 branch에서 기입한 존재하는 branch로 이동
  10. git checkout -b [new branch name] :
    => 새로운 branch를 만들고 만든 branch로 이동
  11. git log :
    => repo.에서 있었던 사항들의 history들을 조회
  12. git fetch --all : git pull 하다가 conflict 났을 때 reset으로 충돌나기 전으로 되돌리기 위해 origin/master가 local/master보다 뒤에 위치하게 됨(merge대기중).
  13. git reset --hard origin/master : origin/master보다 앞에 있는 local/master의 commit은 사라지고 origin/master와 local/master는 충돌 나기 이전의 commit을 가리키고 있음.
  14. git pull origin master : remote repo.의 내용을 정상적으로 merge함.

작업하면서 깨달은 점 및 궁금한 점
1. git push 는 기본적으로 my repo.를 대상으로 함. 다른 repo.에 push하려면 다른 repo.의 github에서 Read 권한을 내 github ID에 별도로 허용해줘야 가능하다. 하지만 안전하게 작업하려면 Pull Request를 받아서 변동 사항 확인 후 Merge하는 게 좋을 것 같다.

! git 은 역시 많이 사용해보면서 익숙해져야 겠다.

profile
웹개발자 James 입니다.

0개의 댓글