Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

signup

login

tour

How to update GitHub forked repository? - Stack Overflow

10/8/2014

help

careers2.0

How to update GitHub forked repository?


Irecentlyforkedaprojectandappliedseveralfixes.Ithencreatedapullrequestwhichwasthenaccepted.
Afewdayslateranotherchangewasmadebyanothercontributor.Somyforkdoesn'tcontainthatchange...
HowcanIgetthatchangeintomyfork?
DoIneedtodeleteandrecreatemyforkwhenIhavefurtherchangestocontribute?oristhereanupdate
button?
github

askedAug30'11at13:53
LeaHayes
6,635 5 26 50

possibleduplicateofgithub,updateforkedproject.CupcakeJul19'13at12:03

10 ThiscanalsobedonefromthegithubUI.I'dliketogivecredit[tothisotherposter][1].[1]:
stackoverflow.com/a/21131381/728141LogicXFeb20at13:00
addacomment

3 Answers
Inyourlocalcloneofyourforkedrepository,youcanaddtheoriginalGitHubrepositoryasa"remote".
("Remotes"arelikenicknamesfortheURLsofrepositories originisone,forexample.)Thenyoucan
fetchallthebranchesfromthatupstreamrepository,andrebaseyourworktocontinueworkingonthe
upstreamversion.Intermsofcommandsthatmightlooklike:
#Addtheremote,callit"upstream":
gitremoteaddupstreamhttps://github.com/whoever/whatever.git
#Fetchallthebranchesofthatremoteintoremotetrackingbranches,
#suchasupstream/master:
gitfetchupstream
#Makesurethatyou'reonyourmasterbranch:
gitcheckoutmaster
#Rewriteyourmasterbranchsothatanycommitsofyoursthat
#aren'talreadyinupstream/masterarereplayedontopofthat
#otherbranch:
gitrebaseupstream/master
Ifyoudon'twanttorewritethehistoryofyourmasterbranch,(forexamplebecauseotherpeoplemayhave
clonedit)thenyoushouldreplacethelastcommandwith gitmergeupstream/master.However,for
makingfurtherpullrequeststhatareascleanaspossible,it'sprobablybettertorebase.

Update:Ifyou'verebasedyourbranchonto upstream/masteryoumayneedtoforcethepushinorder
topushittoyourownforkedrepositoryonGitHub.You'ddothatwith:
gitpushforiginmaster
Youonlyneedtousethe fthefirsttimeafteryou'verebased.
editedDec31'13at11:04

answeredAug30'11at14:01
MarkLongair
98.9k 21 209 210

http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository

1/4

10/8/2014

How to update GitHub forked repository? - Stack Overflow

JustfoundoutabouttheGitHubmacapp(mac.github.com/help)thismakesitveryeasytouseGitHub
LeaHayes Sep9'11at19:39

25 Asyourforkonlyexistsongithub,andgithubdoesnothavetoolsfordoingmergesthroughthewebinterface,
thentherightansweristodotheupstreammergelocallyandpushthechangesbacktoyourfork.
TimKeatingJun19'12at3:50

11 HereisagreattutorialIfoundonworkingwithgithub:gun.io/blog/howtogithubforkbranchandpullrequest
TimKeatingJun19'12at3:55

"GitHubforMacdoesnotsupportmultipleGitremotes.Wewillonlyworkwiththeoriginremote.".Havetosay
that'sapity.luckykevinMar19'13at14:14

Aquicknotethatratherthanhavingtorebaseyourownmasterbranchtoensureyouarestartingwithclean
state,youshouldprobablyworkonaseparatebranchandmakeapullrequestfromthat.Thiskeepsyour
mastercleanforanyfuturemergesanditstopsyoufromhavingtorewritehistorywith fwhichmessesup
everyonethatcouldhaveclonedyourversion.MateuszKowalczykMay29'13at23:09

show11morecomments

Asformayof2014,itispossibletoupdateforkdirectlyfromGitHub.
(fromhttp://www.hpique.com/2013/09/updatingaforkdirectlyfromgithub/)
HereshowtoupdateyourforkdirectlyfromGitHub(asshowninthevideoabove):
1. OpenyourforkonGitHub.
2. ClickonPullRequests.
3. ClickonNewPullRequest.Bydefault,GitHubwillcomparetheoriginalwithyourfork,andthere
shouldntbeanythingtocompareifyoudidntmakeanychanges.
4. Clickonswitchingthebase(ifnochangesweremadeinthefork)orclickEditandswitchthebase
manually.NowGitHubwillcompareyourforkwiththeoriginal,andyoushouldseeallthelatest
changes.
5. ClickonClicktocreateapullrequestforthiscomparisonandassignapredictablenametoyourpull
request(e.g.,Updatefromoriginal).
6. ClickonSendpullrequest.
7. ScrolldownandclickMergepullrequestandfinallyConfirmmerge.Ifyourforkdidnthaveany
changes,youwillbeabletomergeitautomatically.
answeredMay25at7:31
lobzik
731 2 7

1 Thisworkedgreatonetime.Thesecondtimethisprocessdidnotworkthesameway:the"Switchingthebase"
linkdidnotshowup.AndwhenIhit"Clicktocreateapullrequest"itcreatedaPRontheSOURCErepo.NOT
whatIwanted..javadbaAug21at18:14

AsofOctober1,2014thisoptionisnolongeravailable.Probablywasanexperimentalfeaturethatgithub
decidedtonix.javadbaOct4at21:20

IjustdiditonOctober6.StillworksformeMarkC2daysago

addacomment

Hereisgithub'sofficialdocumentonSyncingafork:

Syncing a fork
The Setup
Beforeyoucansync,youneedtoaddaremotethatpointstotheupstreamrepository.Youmayhavedone
thiswhenyouoriginallyforked.
Tip:Syncingyourforkonlyupdatesyourlocalcopyoftherepositoryitdoesnotupdateyourrepositoryon
GitHub.

http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository

2/4

10/8/2014

How to update GitHub forked repository? - Stack Overflow


$gitremotev
#Listthecurrentremotes
originhttps://github.com/user/repo.git(fetch)
originhttps://github.com/user/repo.git(push)
$gitremoteaddupstreamhttps://github.com/otheruser/repo.git
#Setanewremote
$gitremotev
#Verifynewremote
originhttps://github.com/user/repo.git(fetch)
originhttps://github.com/user/repo.git(push)
upstreamhttps://github.com/otheruser/repo.git(fetch)
upstreamhttps://github.com/otheruser/repo.git(push)

Syncing
Therearetwostepsrequiredtosyncyourrepositorywiththeupstream:firstyoumustfetchfromtheremote,
thenyoumustmergethedesiredbranchintoyourlocalbranch.

Fetching
Fetchingfromtheremoterepositorywillbringinitsbranchesandtheirrespectivecommits.Thesearestored
inyourlocalrepositoryunderspecialbranches.
$gitfetchupstream
#Grabtheupstreamremote'sbranches
remote:Countingobjects:75,done.
remote:Compressingobjects:100%(53/53),done.
remote:Total62(delta27),reused44(delta9)
Unpackingobjects:100%(62/62),done.
Fromhttps://github.com/otheruser/repo
*[newbranch]master>upstream/master
Wenowhavetheupstream'smasterbranchstoredinalocalbranch,upstream/master
$gitbranchva
#Listalllocalandremotetrackingbranches
*mastera422352Mylocalcommit
remotes/origin/HEAD>origin/master
remotes/origin/mastera422352Mylocalcommit
remotes/upstream/master5fdff0fSomeupstreamcommit

Merging
Nowthatwehavefetchedtheupstreamrepository,wewanttomergeitschangesintoourlocalbranch.This
willbringthatbranchintosyncwiththeupstream,withoutlosingourlocalchanges.
$gitcheckoutmaster
#Checkoutourlocalmasterbranch
Switchedtobranch'master'
$gitmergeupstream/master
#Mergeupstream'smasterintoourown
Updatinga422352..5fdff0f
Fastforward
README|9
README.md|7++++++
2fileschanged,7insertions(+),9deletions()
deletemode100644README
createmode100644README.md
Ifyourlocalbranchdidn'thaveanyuniquecommits,gitwillinsteadperforma"fastforward":
$gitmergeupstream/master
Updating34e91da..16c56ad
Fastforward
README.md|5+++
1filechanged,3insertions(+),2deletions()
Tip:IfyouwanttoupdateyourrepositoryonGitHub,followtheinstructionshere
answeredOct21'13at23:04
jumpnett
991 6 15

http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository

3/4

10/8/2014

How to update GitHub forked repository? - Stack Overflow


addacomment

Not the answer you're looking for? Browse other questions tagged github or ask your
own question.

http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository

4/4

You might also like