Git:Push
Update remote refs along with associated objects.
자주 사용하는 Git Push 명령어 옵션
-
git push [remote명] [branch명]
- local branch의 내용을 remote 저장소에 push 한다.
-
git push [remote명] [tag명]
- local에 생성한 tag를 remote 에 추가한다.
-
git push [remote명] --tags
- local에 존재하는 tag중에 remote에 존재하지 않는 모든 태그들을 push 한다.
-
git push
<remote명><local branch>
:
<remote branch> - Remote서버에 [Local Branch]를 [Remote Branch]로 Push한다.
Pull vs Fetch
- Fetch: 중앙 저장소의 소스를 로컬 저장소로 가져온다! 그러나 현재 작업중인 소스들을 변경하는 Merge 작업을 하지는 않는다.
- Pull: 중앙 저장소의 소스를 로컬 저장소로 가져온다! 또한 현재 작업중인 소스들의 Merge 작업까지 통합하여 수행한다.
Amending the message of the most recently pushed commit
리모트 저장소의 히스토리를 변경하는 방법은 아래와 같다.
원격 저장소 Revert
원격 저장소에 잘못된 커밋을 올렸을 경우 취소하고 싶다면, 원하는 버전으로 Local branch를 reset한 후 아래와 같이 Push하면 된다.
만약 아래와 같은 로그가 출력되면서 정상적으로 푸시되지 않을 수 있다.
warning: redirecting to https://git.server-project.com:443/yourname/test.git/
Total 0 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To https://git.server-project.com/yourname/test
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.server-project.com/yourname/test'
이 경우 저장소의 Branch가 보호되어 있으므로 해당 저장소의 보호모드를 풀어주면 된다. (Gitlab의 경우 프로젝트 옵션에 들어가면 된다)