16

I created a new branch off an existing PR on github using the browse branches dropdown...typed in an new branch name so it would create a new one based off the PR I was looking at.

I then went locally and did a git checkout -b myBranch

How do I sync up my branch with the remote? I did not name my local branch as the same name as the remote.

git push -u origin my_branch - I assume that's if you already have things synced AND that the local and remote branch names are exactly the same.

So what about my situation?

I tried this but got an error

▶ git branch --set-upstream-to=origin/feature/WA-3 WA-3 error: the requested upstream branch 'origin/feature/WA-3' does not exist

More info to help

The remote branch's name is feature/WA-3 while my local is named W3

▶ git remote show origin

* remote origin
  Fetch URL: https://github.com/xxxx.git
  Push  URL: https://github.com/xxxx.git
  HEAD branch: develop
  Remote branches:
    develop                         tracked
    feature/WA-3                    new (next fetch will store in remotes/origin)
    master                          tracked
    refs/remotes/origin/w9-homepage stale (use 'git remote prune' to remove)
    w1-log-in              tracked
    wa-9                  tracked
  Local branches configured for 'git pull':
    develop            merges with remote develop
    w1-log-in merges with remote w1-user-can-log-in
    w9-homepage        merges with remote wa-9-homepage
  Local refs configured for 'git push':
    develop            pushes to develop            (up to date)
    w1-log-in pushes to w1-log-in (up to date)

enter image description here

PositiveGuy
  • 14,005
  • 18
  • 67
  • 121
  • `new (next fetch will store in remotes/origin)` sounds weird. Have you tried to fetch? – choroba Jun 01 '17 at 22:13
  • Does this answer your question? [How can I push a local Git branch to a remote with a different name easily?](https://stackoverflow.com/questions/5738797/how-can-i-push-a-local-git-branch-to-a-remote-with-a-different-name-easily) – pkamb May 19 '20 at 07:24

1 Answers1

28

Use the colon notation:

git push -u origin local_branch:remote_branch
choroba
  • 216,930
  • 22
  • 195
  • 267
  • ▶ git branch -u feature/WA-3:WA-3 error: the requested upstream branch 'feature/WA-3:WA-3' does not exist – PositiveGuy Jun 01 '17 at 21:46
  • is that a bad name I gave it in github? why can't it find it? – PositiveGuy Jun 01 '17 at 21:46
  • I literally named the remote branch as `feature/WA-3` – PositiveGuy Jun 01 '17 at 21:47
  • how weird, I see the branch on github yet when I do this it's not listing that particular branch:" `▶ git branch -r origin/HEAD -> origin/develop origin/develop origin/master origin/w1-log-in origin/w9 origin/wa-9-homepage` – PositiveGuy Jun 01 '17 at 21:49
  • I really can't believe this. I deleted the remote and re-created a new branch off that PR called simply `W3` and same deal it doesn't even see it when I do a `git branch -r` – PositiveGuy Jun 01 '17 at 21:53
  • ok yours works ▶ git push -u origin WA-3:WA-3 Branch WA-3 set up to track remote branch WA-3 from origin. – PositiveGuy Jun 01 '17 at 21:54