You might find yourself in a situation where you have a branch that you created locally and want to push to a remote git repository. Suppose you created a local plugin
branch that you want to expose to others through your GitHub repository but you are not yet confident enough to put it into the master branch. Here is the command you would execute to push all of the changes from your plugin
branch to a plugin
branch on the GitHub repository:
git push -u origin plugin
This tells git to push changes from your plugin branch to the plugin branch on the origin repository. If origin does not have a plugin branch, it is created on the fly. The -u tells git that you want to be able to easily push and pull changes to that branch in the future.
Now, say your friend Bob wants to access the hot new feature you just pushed to the new branch on the GitHub repository. All Bob needs to do is update his local repository with all of the changes on the GitHub repository and create a local branch where he can play with the new code.
git fetch origin
git checkout --track origin/plugin
The first command updates Bob's repository with the changes from the remote repository. The second command creates a local branch named plugin
that matches the origin/plugin
branch and tells git that Bob wants to be able to easily push and pull from the branch on GitHub. Bob can now play with the code, commit his own changes and git push
them back up to the GitHub repository.
UPDATE: As Andy mentioned, you probably want to set the upstream so you can easily interact with the remote branch in the future. Hence, I added -u to the original git push example.