简体   繁体   中英

Get Origin Repo's Master as a branch of my fork in Git

I'm familiar with the basics of git, but not the advanced stuff, and I'm a bit lost here. While I do my checkouts and commits and clones on the command line, I honestly use the Github UI for forking and merging with other repos.

So my problem is this: A while back I cloned a repo, let's call it Upstream , and made some changes. Let's call my fork Downstream. I submitted my code as a pull request, but Upstream didn't want my changes. Oh well, now I maintain Downstream for myself and a few other users who want the functionality I added. Every now and then I pull down the changes from Upstream/master into Donwstream/master .

Now, I'd like to do some more work on Upstream , and once again submit my changes as a pull request to them. However, my master has changes they've already said they don't want, so I want to re-fork their master into a new branch on Downstream (ie, Downstream/upstream-master ). How would I do this?

  1. If your repository doesn't currently have the upstream remote, git remote add upstream https://github.com/Foo/Bar.git and then git fetch upstream .
  2. Get the code from upstream: git checkout upstream/master
  3. Make a new local branch that points to the code you just checkout out: git checkout -b upstream-master
  4. [Optional] Cherry pick your work from your old branch onto the one you just made. git cherry-pick abc123

I left these as separate commands for simplicity, but there is probably a way to combine them into a single command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM