DEV Community

Shivam Singhal
Shivam Singhal

Posted on • Updated on

How to get rid of branch name from git push origin master

We always type git push origin master, while working on feature branch we type git push origin JIRA-1, sometimes the names of the feature branch is not easy then we use git push origin this-branch-will-do-something to push the code over GitHub or any other hosting service. In each case, we are doing redundant work of copy-pasting or typing branch name which is redundant and annoying as you have to remember the branch name exactly or you might end up pushing the code to the wrong branch. This can be handled by just with one command,

git config push.default current
Enter fullscreen mode Exit fullscreen mode

So this command push changes to .gitconfig file and after change git config file looks like this:

[user]
  name = author
  email = author@itsopensource.com

[push]
  default = current
Enter fullscreen mode Exit fullscreen mode

You can directly append in git config too.

After this, all you need to do is:

git push origin
Enter fullscreen mode Exit fullscreen mode

Note - If you do this inside a git repo, this will only be available for that repo, if you want to do it globally and add --global flag:

git config --global push.default current
Enter fullscreen mode Exit fullscreen mode

This will make these changes to be set globally across all the git repos you are using.

Happy git!

Originally published at https://itsopensource.com.

Top comments (0)