Just stop 🤬 There is a better way of doing it! Fire one command and spare few seconds multiplied by a hundred times. Welcome to my shortest post on this blog.
The problem and the solution
So after a few years of creating new branches and pushing them to the origin, I realized that I am doing a strange thing each time. Let’s begin the simulation.
- Create the branch locally.
- Do some changes, commit them.
- Time to push the changes:
1$ git push
2fatal: The current branch feature/a_branch has no upstream branch.
3To push the current branch and set the remote as upstream, use
4
5 git push --set-upstream origin feature/a_branch
- Copy the output command, paste it, execute again or retype with a shortcut:
git push -u origin feature/a_branch
- Done
Point 4 is just stupid, isn’t it? Luckily according to git docs [1] we have a nice setting named push.default
which we can set to current
:
Push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.
It is enough to run this command:
1git config --global push.default current
To set automatic tracking (so You can pull changes from the origin) run this:
1git config --global push.autoSetupRemote true
Done. Years of copy & pasting the output command are gone. You might want to see if the configuration is correct using
1git config --global --list
You can of course apply this setting only to the selected repository. In this case, your working directory should be your repository and you should omit the --global
argument. Cheers!
Conclusions
It is always worth to challenge your routine habits. The second conclusion is that it is worth to get know the tools you use 😅.
References:
Websites:
[1] Git configuration documentation