실무에서 (제가) 자주 사용하는 git 명령어
실무에서 (제가) 자주 사용하는 git 명령어

실무에서 (제가) 자주 사용하는 git 명령어

Created
2022/03/11
Tags
git
git command
 
 
2022-03-11 @이영훈
 
git과 더 나아가 git flow를 잘 사용하여 개발 프로젝트 관리를 더 잘 하고 더 적게 일을 하고 더 많은 것을 얻어가면 좋겠습니다
git을 잘 사용하셔서 개발 프로젝트 관리를 더 잘 하고 더 적게 일을 하고 더 많은 것을 얻어가시면 좋겠습니다
 
 

일반적인 git command

  1. git add: stage에 추가하는 명령어
    1. Bash
      git add .  // 현재 경로를 포함하여 모든 sub-directory 
      git add facny.service.ts
  1. git reset: stage에서 빼는 명령어 (unstage)
  1. git rm: 로컬과 remote 모두에서 파일을 삭제하는 명령어
    1. 당연히 push해야 remote에서도 제거가 됩니다
    2. 로컬 파일은 유지하고 싶으면 git rm --cache
    3. Bash
      git rm --cached .DS_Store
  1. git rebase : 갈라져 나온 조상 브랜치의 최신 것으로 만들고 브랜치를 합칩니다
    1. Bash
      (@origin/feature) git rebase develop   # 'feature' 브랜치를 -> 'develop' 브랜치로 합치기
  1. git commit : 내용을 커밋합니다.
  1. git push : 커밋 내역을 원격 저장소(remote repository)에 저장합니다.
  1. git checkout : 브랜치를 변경하거나 워킹 트리 파일을 복원합니다. (git switch + git restore)
  1. git switch : 브랜치를 변경합니다.
  1. git restore : 워킹 트리의 파일을 복원합니다.
 
 

git stash

  1. git stash : 현재 작업 내역을 임시로 저장합니다
  1. git stash list : stash 내역을 확인합니다
    1. notion image
  1. git stash pop : stash 내역을 가져오고 stash를 삭제합니다
    1. Bash
      git stash pop stash@{0}
  1. git stash apply : stash 내역을 가져오고 stash를 유지합니다
    1. Bash
      git stash apply stash@{1}
  1. git stash drop : stash를 삭제합니다
    1. Bash
      git stash drop stash@{2}
 
 
 

upstream에서 코드 가져오기

  1. git remote -v
    1. notion image
  1. git remote add [origin] [address]
    1. Bash
      git remote add upstream https://github.com/owner/repository-name.git
  1. git fetch [origin]
    1. Bash
      git fetch upstream
      
      # (참고) 모든 remote origin의 코드 가져오기 (git fetch upstream + git fetch origin)
      git remote update
  1. git merge [origin/branch]
    1. Bash
      (@origin/develop) git merge upstream/develop
      
      git checkout main
      (@origin/main) git merge upstream/main
 
 
 

Ref.