Learn Version Control with Git
A step-by-step course for the complete beginner
Publishing a Local Branch
A local branch that you create on your machine is kept private to you until you explicitly decide to publish it. This means that it's perfectly possible to keep some of your work private while sharing only certain other branches with the world.
Let's share our "contact-form" branch (which hasn't been published until now) on the "origin" remote:
$ git checkout contact-form Switched to branch 'contact-form' $ git push -u origin contact-form Counting objects: 36, done. Delta compression using up to 4 threads. Compressing objects: 100% (31/31), done. Writing objects: 100% (36/36), 90.67 KiB, done. Total 36 (delta 12), reused 0 (delta 0) Unpacking objects: 100% (36/36), done. To file://Users/tobidobi/Desktop/GitCrashkurs/remote-test.git * [new branch] contact-form -> contact-form Branch contact-form set up to track remote branch contact-form from origin.
This command tells Git to publish our current local HEAD branch on the "origin" remote under the name "contact-form" (it makes sense to keep names between local branches and their remote counterparts the same).
The "-u" flag establishes a tracking connection between that newly created branch on the remote and our local "contact-form" branch. Performing the "git branch" command with a special set of options also shows us the tracking relationships in square brackets:
$ git branch -vva * contact-form 56eddd1 [origin/contact-form] Add new contact.. faq-content 814927a [crash-course-remote/faq-content: ahead 1] Add new question master 2dfe283 Implement the new login box remotes/crash-course-remote/faq-content e29fb3f Add FAQ questions remotes/crash-course-remote/master 2b504be Change headlines f... remotes/origin/contact-form 56eddd1 Add new contact fo... remotes/origin/master 56eddd1 Add new contact form page
After having created that new remote branch like this, updating it with new local commits that you create in the future is easy: simply call the "git push" command with no options as we did in our earlier example.
Anyone with access to your remote repository can now also start working on "contact-form": he can create a local branch on his machine that tracks this remote branch and also push changes to it.