【Git Snippets】Set default push branch name

273 阅读1分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

The Git snippet collection contains a variety of short tips and tricks for all currently maintained versions of git. It includes most commonly-used commands and covers various use-cases in the form of simplified documentation, complete with multiple examples.

Short code snippets for all your development needs.

Use the name of the current branch when pushing by default as the name of the remote branch.

  • Use git config push.default current to set the name of the remote branch to the one of the current local branch as the default.
  • You can use the --global flag to configure this option globally.
$ git config [--global] push.default current

Example

$ git config --global push.default current

$ git checkout -b my-branch
$ git push -u

Then pushes to origin/my-branch!

Original state:

State changed:

🧠Wish you can benefit from this article.
🔥 And welcome to leave your thoughts in the comments section that we can discuss and share ideas with each other.