Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Understanding meaning of syntax of git push

Situation

  1. I have 2 local branches A and B.
  2. I have 2 remote branches C and D.
  3. The name of my remote is origin.
  4. If I want to push changes from my branch B to remote branch D, what should be the git push syntax? I am confused among the following options
  • git push origin B:D
  • git push origin B/D
  • git push origin B
  • git push origin D

Please help me in understanding the correct git push syntax as well as its meaning

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The technical description for this syntax is in the Git manual under "The Refspec" and the argument description of git push, but the short version is that there are two common formats:

  • A pair of branch names in the form source:destination, e.g. git push origin B:D means "source is the local branch B; destination is the remote branch D".
  • A single branch name, which is (unless configured specially) shorthand for source and destination having the same name, e.g. git push origin B is the same as git push origin B:B, and means "source is the local branch B; destination is the remote branch B".

Specifying B/D would look for a branch with that name, e.g. some projects have naming conventions like "username/task-number"). However, you may be confusing it with "remote tracking branches", which take the form "remote-name/remote-branch-name", such as "origin/D"; you wouldn’t normally be using those in a git push command.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading