Only push what you really want
Git default behavior is to push all the branches to that have the same name in the remote, so if you're working on a branch and you want to push it, you need to be specific otherwise it will also push master (or any other branch), which is usually not what you want.
The way I fix that is by setting git's config 'push.default' to 'upstream':
git config --global push.default upstream
With this "git push" will always push only the current branch and to the defined upstream branch, which you need to set manually once but its easy and painless.
If you're pushing a new branch, set the upstream with -u in the first push you do:
git push -u origin branch_name
I usually set the branch name to the same as the local branch, if you have bash completion you can just type tab.
If you're checking out an existing branch from remote:
git checkout -t origin/branch_name
If you're on latest git, you can even do:
git checkout branch_name
And you will see it setup tracking as well:
Branch branch_name set up to track remote branch branch_name from origin.
Written by Rodrigo Kochenburger
Related protips
1 Response
Nice. I didn't know that. Btw 'upstream' only works on newer versions of git. Use 'tracking' if you are not on the latest git.