Dan
Dan

Reputation: 367

re-sync fork with parent git repo

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?

Upvotes: 0

Views: 3261

Answers (2)

Dan
Dan

Reputation: 367

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

Upvotes: 0

Thomas Kelley
Thomas Kelley

Reputation: 10292

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 [email protected]: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.

Upvotes: 1

Related Questions