0

I have forked a repo on github and the repo I have forked from has since added a new branch. I would like to get that branch into my local fork and work on it. Afterwards I would like to commit to that branch (which is in my local fork) and then submit a pull request to the original parent repo.

What ends up happening when I try to do this is as follows

  1. Fork from parent repo
  2. Parent repo then makes a new branch
  3. On my local machine I do: git remote add parent https://github.com/PARENT/parentProj.git
  4. git pull parent [new branch name]
  5. Now I try: git checkout [new branch name] and I get "Branch [new branch name] set up to track remote branch [new branch name] from parent. Switched to a new branch '[new branch name]'
  6. I think I am good but I am not. Now when I make my changes and git push I get "remote: Permission to PARENT/parentProj.git denied to [me]."

I believe it is trying to push to the parent project new branch and not my fork of it.

How do I get it to let me push to the new branch on my fork so that I can then issue a pull request?

Dan
  • 367
  • 3
  • 7

2 Answers2

1

When you do a git branch -avv, Git will show you which remote branches your local branches are "connected to".

$> git branch -avv
* master                a1b2c3d [origin/master] Some commit message here

That [origin/master] part means that if you update this branch, and attempt a git push, that's where it'll try to push.

In your case, I'd suggest re-assigning that remote's URL, but for push only. It seems you're always going to want to fetch from the parent fork, and push to your local, correct? If that's the case, then try this:

git remote set-url --push origin git@github.com:YourUser/theRepository.git

This way, when you pull, it comes from the parent fork, and when you push, it goes to your own fork. Then, you use the pull-request mechanism to get your code from your local fork to the parent.

Thomas Kelley
  • 10,187
  • 1
  • 36
  • 43
  • That is kind of what I want but not quite. Really I just want to tell my fork to re get all of the things from the parent. Commits, branches, etc. As if I had blown away my entire fork and redone it. That is the only way I have found to get everything all synced up correctly, but was hoping there was a better way. – Dan Mar 05 '14 at 15:18
0

Turns out I should have just searched more (or known better what to search for). This answer solved my problem: Github: Import upstream branch into fork

Community
  • 1
  • 1
Dan
  • 367
  • 3
  • 7