简体   繁体   中英

How to do a pull request from a forked repository

I'm a bit new with Git and need some help. I have forked an online respository that I'm using in my own project. Now and then I would like to make some pull requests to the original repo, but as I've made local changes in my fork that I don't want in the pull requests, I'm a bit unsure of the process.

Can I create a pull request from a branch made from my local version, and merge that with the upstream? Or would I basically have to check out the original repo, make the changes, and make a pull request from this branch? This meaning, I would effectively do the changes twice – once for my local fork, and once in a branch that I make a pull request from. Is there a way to do the changes once, and apply them both places, even though the fork is ahead of the original repo?

I tried the first version, but I guess that would bring with it other changes from my fork, which I guess makes sense.

If you don't have a remote for upstream yet, you can add it using git remote add upstream <url> . This way your local repo gets two remotes, origin (fork) and upstream. Use git fetch upstream to update the remote branches for upstream .

You should now branch out from upstream/master (or whatever their default branch is), to get rid of commits in your fork that you don't want in the PR. You can then use git cherry-pick to "transfer" specific commits from one branch to another. Now you can push this branch to origin, and open a PR in upstream.

Make sure to check that you got the correct changes when you're opening the PR

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