How to copy a new branch from the original repo to my forked version on GitHub?

Hey folks, I need some help with GitHub forks. I’ve got this project I forked a while back, but now the original repo has a new branch I want to add to my fork. I’m not sure how to do this.

I tried something like:

git checkout original-repo/new-branch
git checkout -b new-branch

But that’s not working right. It’s trying to push back to the original repo when I do git push, which isn’t what I want.

What I’m trying to do is get that new branch into my local repo so I can push it to my fork on GitHub. You know, since we can’t usually write to the original repo directly.

Any ideas on how to set up a new branch in my fork that matches the one from the original repo? Thanks!

yo danielr, i gotchu. add the OG repo as remote: git remote add upstream . then fetch: git fetch upstream. make new branch: git checkout -b new-branch upstream/new-branch. finally push: git push -u origin new-branch. shud work!

I’ve dealt with this situation quite a few times. Here’s what I usually do:

First, make sure you’re in your local fork directory. Then, add the original repo as a remote if you haven’t already:

git remote add upstream

Now, fetch all the branches from the upstream:

git fetch upstream

This brings down all the new branches without merging them. Then, create a new local branch that tracks the upstream branch:

git checkout -b new-branch --track upstream/new-branch

At this point, you’ve got the new branch locally. To get it on your GitHub fork, just push:

git push origin new-branch

This method has always worked smoothly for me. It keeps your fork updated and lets you work with new branches easily. Just remember to periodically sync your fork to stay current with the original repo.

I’ve encountered this issue before. Here’s a solution that worked for me:

First, ensure your local fork is up-to-date with the original repository. Add the original repo as a remote if you haven’t already:

git remote add upstream

Then, fetch the updates and checkout the new branch:

git fetch upstream
git checkout -b new-branch upstream/new-branch

Now you have the new branch locally. To push it to your fork on GitHub:

git push -u origin new-branch

This should create the new branch in your fork, matching the one from the original repository. Remember to keep your fork synced regularly to avoid falling behind on updates.

hey danielr, try adding the original as remote: git remote add upstream then fetch new-branch with git fetch upstream new-branch:new-branch and finally git push origin new-branch. hope this helps!