10

My workflow with new branches is:

git checkout -b <new branch name> // making changes, commit the changes git push -u origin <new branch name> 

Is there any way to push the local branch to a new remote branch without writing the name of the branch again (local and remote branch will have the same name)? Everyday I make at least 1 feature branch with really long name and at the end of the day I have to go back to JIRA board to get project IDs and other things required for the convention. I'm just curious if there is some hack to get the local branch name and pass it directly to git push -u origin <local branch name>

6
  • 1
    If your branch is configured with an upstream, git push is sufficient. Commented Apr 13, 2020 at 17:14
  • 1
    Does this answer your question? Why do I need to do `--set-upstream` all the time? Commented Apr 13, 2020 at 17:14
  • Might also want to read stackoverflow.com/questions/948354/… Commented Apr 13, 2020 at 17:16
  • Thanks to both of you. I know that I have to write it once per branch, but I was thinking about a shortcut for creating the remote branch with the exact name as the local branch. It happens to copy something else or if I write something by convention, by accident to click enter while writing the name of the remote branch. Then I need to go and delete the remote. IDK. I wanted some trick to get the local branch's name while creating the remote branch to automate the process of writing the same name of the branch again. Commented Apr 13, 2020 at 17:27
  • "but I was thinking about a shortcut for creating the remote branch with the exact name as the local branch" But the remote branch always automatically has the same exact name as the local branch, so what's the problem? If push.default is current, you just say git push -u and you're all set. Commented Apr 13, 2020 at 17:45

3 Answers 3

19

I do this, HEAD automatically refers to your current branch (technically current commit, but don't worry about that)

git push -u origin HEAD

Sign up to request clarification or add additional context in comments.

Comments

6

Try git config --global push.default current and then just git push -u origin

Comments

-1

To push the current branch and set the remote as upstream, use below command:

git push --set-upstream origin yourBranchName 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.