2

I'm having an issue where I'm trying to push a local branch to a remote branch so that I can then create a pull request into master. I'm using:

git push origin brachname

This seems to fail, and instead is pushing to the master remote branch (which isn't great). If I reference the local and remote branches explicitly (ie: branchname:branchname) it works fine. It seems that either I have something off with my git config, or there's something wrong with the way I'm creating my local branches.

Any help would be appreciated.

CodeWizard
  • 92,491
  • 19
  • 110
  • 133
Zepee
  • 1,362
  • 2
  • 15
  • 36
  • possible duplicate of [Push a new local branch to a remote Git repo and track it too](http://stackoverflow.com/questions/2765421/push-a-new-local-branch-to-a-remote-git-repo-and-track-it-too) – tanaydin Jun 01 '15 at 13:15
  • 1
    The command looks just fine. So how _do_ you create your local branches? – arkascha Jun 01 '15 at 13:19
  • Which branch does it think it's tracking? http://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking – James Bateson Mar 23 '16 at 10:32

2 Answers2

1

Looks like you are on the master branch and trying to push it to another branch.

How to be able to push to different branch name?

Set/Update the tracking branch

git < 1.8:
git branch --set-upstream branch_name remote/branch_name

git > 1.8:
git branch branch_name --set-upstream-to remote/branch_name

Your current tracking information is inside your .git/config file


Create a new branch with the desired name

git checkout -b <new_branch>
git push origin <new_branch>

git will push to the remote branch your current branch name (assuming you did not changed the tracking branch)


Renaming the branch (so the tracking branch will be updated too)

Or you can use the -u switch:
git branch branch_name -u remote/branch_name


Community
  • 1
  • 1
CodeWizard
  • 92,491
  • 19
  • 110
  • 133
0

Try the below

 git push -u origin <branch_name>

If you have permission to push a local branch onto remote repo, it should go through

Mayur Nagekar
  • 797
  • 4
  • 13