Skip to content
Search

Git:Push

lastmod 2025-02-14created 2014-03-017 edits

Update remote refs along with associated objects.

Frequently used Git Push command options

git push [remote명] [branch명]
Pushes the contents of a local branch to the remote repository.
git push [remote명] [tag명]
Adds a tag created locally to the remote.
git push [remote명] --tags
Pushes all local tags that do not exist on the remote.
git push<remote name><local branch>:<remote branch>
Pushes [Local Branch] to [Remote Branch] on the remote server.

Pull vs Fetch

  • Fetch: Brings the source from the central repository into the local repository! However, it does not perform a Merge that changes the sources you are currently working on.
  • Pull: Brings the source from the central repository into the local repository! It also performs the Merge of the sources you are currently working on.

Amending the message of the most recently pushed commit

To change the history of a remote repository:

$ git commit --amend -m "Change commit message."
$ git push --force [REMOTE_NAME] [BRANCH_NAME]

Reverting a remote repository

To undo a bad commit pushed to the remote repository, reset the local branch to the desired version and then push as follows.

$ git push origin master --force

The push may fail with a log like the following.

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'

In this case the repository's branch is protected, so turn off the protection for that repository. (For Gitlab, go to the project options.)

Favorite site

author Zer0 sitemap