When I'm using a local branch mybranch
, I'd like to be able to push to and pull from origin mybranch
using just git push
and git pull
. As it is, I have to tediously write out git push origin mybranch
and git pull origin mybranch
. If I try to use just git pull
for example, I get:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> mybranch
And if I enter git branch --set-upstream-to=origin/mybranch mybranch
, then it works. But this is almost as tedious as the previous commands. Can I just have git do this as default behavior? I've seen similar questions asked and the answers tend to suggest that newer versions of git do this, but I'm using git version 2.1.3, which is fairly new, so it can't just be that.
One possible solution is to modify your git push behavior to current
(note that this will also have some other side affects). You can do that either by modifying your ~/.gitconfig
directly(as a file and this assumes you are on linux) or by executing:
git config --global push.default current
Now when you push
, git will automatically push your current branch to a remote branch with the same name even if you don't specify it explicitly. In addition if your current branch does not have a remote equivalent, a remote branch will be created and your current branch will be set to track it(same as git push -u origin new_branch
but with a single git push
). Also have a look at this question where the git push behavior is described in detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With