git tips: configure current branch for push and pull
When working in a standard git flow that could be quite cumbersome to enter the name of current branch each time you pull and push to remote repository.
In this post I will show how to set the name of current branch once and use commands ‘git pull’ and ‘git push’ without specifying branch name.
First we need to set current branch as default for git pull
git config push.default current
Now check the the current configuration:
git config push.default
Should print ‘current’.
We can check that branch name is now not required anymore when we push:
When working on new branch for first push you need to set the remote as upstream:
git push --set-upstream origin DEV-1558-move-vk-link
This way we configured push command to automatically figure the remote branch name.
Now you can pass
-u and it will also automatically set the tracking branch. (source)
git push -u
Everything up-to-dateBranch 'DEV-1585-correctives' set up to track remote branch 'DEV-1585-correctives' from 'origin'.
According to git push documentation the -u option add upstream (tracking) reference, used by argument-less git-pull(1) and other commands.
Now pull command will look like that