What does refs/heads/master:refs/heads/master mean?

Viewed 2825

As a rule, I use Git via command line. Today, I decided to use it with NetBeans IDE which generated the following command:

git push ssh://...myrepo.git/ refs/heads/master:refs/heads/master

Could anyone explain what refs/heads/master:refs/heads/master means?

2 Answers

The syntax used is as follows: git push <repository> <src-ref>:<dst-ref>

By using refs/heads/master as both <src-ref> and <dst-ref>, Git works with qualified and explicit refspecs (locally and on the remote) and does not need to guess the namespace based on source and destination refspecs. Additionally, the repository is explicitly provided which means that it is not addressed by a configured name (like origin).


Let's see this in action in a demo repository. The branch dev is checked out and the remote was removed after cloning. First, we list references in the (explicitly provided) remote repository and see that all refs are pointing to 7b7d5a3. The log of git-push shows that we update 7b7d5a3..4a27218 on the remote master branch while no remote is configured and standing on the dev branch. Listing the references on the remote again confirms this.

$ git branch -va
* dev    7b7d5a3 Initial commit
  master 4a27218 Add file.txt

$ git ls-remote git@domain.tld:user/repo.git
7b7d5a33d6e6ea3d69d9f87fa8ef1c596a37e24c    HEAD
7b7d5a33d6e6ea3d69d9f87fa8ef1c596a37e24c    refs/heads/dev
7b7d5a33d6e6ea3d69d9f87fa8ef1c596a37e24c    refs/heads/master

$ git push -v git@domain.tld:user/repo.git refs/heads/master:refs/heads/master
Pushing to git@domain.tld:user/repo.git
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 294 bytes | 294.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To domain.tld:user/repo.git
   7b7d5a3..4a27218  master -> master

$ git ls-remote git@domain.tld:user/repo.git 
4a272186f7f56f2346fb2df7e63584f09936bdad    HEAD
7b7d5a33d6e6ea3d69d9f87fa8ef1c596a37e24c    refs/heads/dev
4a272186f7f56f2346fb2df7e63584f09936bdad    refs/heads/master

You're pushing the branch called 'master' locally to a remote repo where the branch is also called 'master'.

Normally, your branch would have an upstream in which case this syntax would not be necessary.

Related