git - How do you update upstream with changes from fork? -
i have main repository a, forked repository b. i've made changes in b want move a. i'm having hard time figuring out how this.
first, git commands this?
second, can pull request in github facilitate this? how work?
finally, had branch in b wanted merge. should merge branch in b master branch before doing merge/pull request upstream repository (a)?
there 2 main ways of doing this
- merge client side , interact multiple remotes
- merge server side pull requests, , interact 1 remote
before read on i'd question relatively open-ended , there not single best answer it. following answer reflect of workflows i've used give insight.
client side
supposing working on clone of b, can add second remote:
git remote add repo_a <repo url>
repo_a
alias remote repository, origin
currrent alias remote b. let's rename origin
repo_b
sake of clarity:
git remote rename origin repo_b
list remotes:
git remote -v
fetch stuff both remotes
git fetch repo_a git fetch repo_b
at point, can create local branches track branches both remote repositories without restrictions on way merge, or merge. how define workflow add constraints.
if, say, you'd merge changes repo b's feature_1
branch repo_a
's master
branch, do:
git checkout -b master_a repo_a/master --track git merge feature_1 git push repo_a master_a:master
you're biggest friend gitk
or other graphical tool display local branches , remote branches in same view. suggest opening detached gitk
, refreshing need. don't forget --all
option.
gitk --all &
server side (pull requests)
in next example, client-side commands take place in local clone of repo_b
. push features repo_b
on github , use pull requests merge.
when work pull requests have repo_b
's master branch in sync parent repository , it's common use upstream
, origin
in repo_b
's client side clone:
git remote add upstream <repo url>
reset master branch upstream
:
git fetch upstream git fetch origin git checkout master git reset --hard upstream/master git checkout -b feature_2
implement feature , push github:
git push origin feature_2
now in web interface should have option submit pull request when viewing branch. won't go through details should intuitive enough. select repo_b/feature_2
source , repo_a/master
destination.
when merge done, can update master
branch in clone of repo_b
:
git fetch origin git checkout master git merge origin/master
Comments
Post a Comment