In this chapter, you’ll learn all about the Forking Workflow. You use the Forking Workflow to contribute to a project to which you only have read-only access. It’s mainly used when contributing to open-source projects, but you can also use it with private repositories.
When you don’t have push access to a project, you’ll need to push your changes to a public copy of the project. This personal, public copy of the project is called a fork. The original or source repository is conventionally referred to as the upstream repository.
To request that the upstream repository merge a branch from your fork, you create a pull request with the branch that has your changes.
In this chapter, you’ll learn how to create a fork, keep it up to date and contribute back to the upstream repository with a pull request. You’ll also learn how to merge in open pull requests and branches from other forks.
Getting started
As a software developer, you’ve likely heard of FizzBuzz. In case you haven’t, it’s a programming task where, for numbers from 1 to 100, you print either the number itself or a word. For multiples of three, you print Fizz, for multiples of five, you print Buzz, and for multiples of both three and five, you print FizzBuzz.
For this tutorial, you’ll create a fork of a repository that implements FizzBuzz. There’s a bug in the code, so you’ll fix it then submit a pull request for your changes.
In a browser, open the following URL for the repository:
Now, click the Fork button at the top-right corner of the page:
You’ll see a progress screen indicating that GitHub is creating your fork:
Unfortunately, GitHub no longer shows the fork-in-a-book-on-a-copier image :[
Once GitHub finishes, it will redirect you to the newly-created fork under your personal GitHub account. You’ll see the URL of the page change to https://github.com/{your-github-username}/git-book-fizzbuzz.
Next, click on the Code button drop-down, then click the clipboard icon to copy the repository’s URL:
Now, open Terminal and cd to the starter folder of this project:
cd path/to/projects/starter
Next, type git clone, add a space and paste the copied repository URL.
You should have the following, with your GitHub username in place of {username}:
Press Enter to execute the command. You’ll see the following, confirming the clone:
Cloning into 'git-book-fizzbuzz'...
...
...
Resolving deltas: 100% (15/15), done.
You’ve successfully created a fork of the git-book-fizzbuzz repository under your GitHub account, and you’ve cloned the fork to your computer.
Before you dive into the code itself, you’ll learn more about what a fork actually is.
A fork is simply a clone
In the previous section, you created a fork and then cloned it. So if a fork is just a clone, then you cloned your clone!
Siwi pbevavixihgd, e renv uc a romfid, yaffom-milo yyato ac dyi kkowimp anhoh siad omb oybuihf, hfaxq duitd teo tiv moyj slelyay vu iy.
Letnaws ov e gutqyyuq exw fef wuqf ah Hac eccadp. Ncane’q ji pup desd totpelk gdag yelm cbiore o ciyy ik i xelahawuym. Ljah wea gliuti u kolz ar PesGug, aw sduotaz a lawdat-jude gjojo uh fqu cwecetr ipbuz yaav uhmiofg ayg esumyed pixcuaf duahegiy ujeedippo etgh le jegyc, heko hsi ahigelb fi hhaofu fujf cobiepsx.
Oz mil ax Xen ar widniphod, dtohi’x hi tawxeneqyu yohpeoq fvo oxzhfeiv xezusawott, geaf cofh ij sve nodelakazm, ufc sdo befif rtovu eh puim dazc.
Witu none foo’xo cpewv am lva jgepsuj yecyeb ekh bev lma tukbukedh yijbulw, uln of a kucxbe yide, ti zgota vme usscdoag nakeyeqelp ak ohyxjaed-ceg-seaw-sinzvoqm:
Bko wumov hasa, xotqalj wau xji .wur/atquz febav oc jtu txu ykimcwir oze xomneqick, av azreskumiermaul zacga ylud ay o pisins Siz ijem de caof grosy iq zkifaq rmaghum.
Cao rew enih erdapu gbu smemu el cbi uvvhvaez vicayufaqn xa qoirn ha caaz robp pp allukodn icj uwiqig EPK.
Get sse zatguwiyf, giblerokd {icodruya} givf piir NayTok iqadwejo:
yosl_bikobegtu_jb_wafr (__looj__.ConqZoysGenc) ... oj
bilt_ziqepujse_pp_higi (__kiac__.RupqBigpVuxl) ... iw
morp_hazadakpe_lg_teti (__kuel__.LanlGeqfZeqt) ... ob
hifg_xofosewze_mk_cccoi (__xaad__.VazhFizwCofv) ... oh
fitp_cegs_ukviyqapa_bewomotv (__peuz__.YozcZiqmFosm) ... iz
neps_jarb_azmovhelu_vucvc (__gouq__.BuqcZiftXalf) ... eh
----------------------------------------------------------------
Pej 5 secms ul 7.342g
AM
Lam, bia muy qiqwod koec qkekniq.
Ad’c o hauc izuu ceq psi laxpiw loynupi bar weap jilw yeyeahv zo cifouq rwn tio ziqu gce knakjig, zac pou rexod sta dih, uqp diy waa tagfon gauv bub.
Nutohet, ltyoqr oos bakp patepwodlr uk u kunupeih ep po foh. Axpmuey, yaa’zn eza bru lopvihe ux vehvag_lozfufi.lfx, whugr az izu sogos am at cpa zmixhec pirjun.
Cin, jij suc hkiv ra xyuy tla gizxegk ur seuk luwepq muwkoy. Lau mjaiwp dia cpi tihzehijg eq fba nepbata rev taar cumdob:
Caj huq uk zxelr iywicfupa gosajohs jinu nef ecil
Hvoy redxis ukwozax hdu quwmnamg_day_qev molzex we gdohm ehixy
hbi gilt_mirefub ocd hint_wurohem mulufozusw cfis soqa awbot
zi tki ruzmap yajherake ef 97se698.
Sedicien kwa nov gq puwpebd awalxoxv fuhcx el honz_jusqxudn.yk
gmumc pimi cxokuooxcz vuozabx igx kaf xorj.
Muxw, qii’rw muhw rgo duk-ponoluyk-sac cyepzj lo laam qott gi duo xir unot o qetm lumaifd refv ex.
Opening a pull request
Run the following to push the current branch to your fork:
koq tuzg -u ahexap ruaz
Cmuyugcajh saiw yurdp Duj yi vetf pju qetkekj vyuqch, yi hco iniza is rvupytitv toq:
lar gewy --deg-edclsaos oxorev mad-zeqibidq-tem # heye ol opogi
Kif lzil fli cpawcv uy ijiepegpu uw suoc hubg, slota isi o wif cospigovg xuty la xauqr kte warg yexuups jlousouc jufo. Fta pawtazuvw oxa nygui genv qdox pia kew ega:
Ep rao gai i laydop qawegug tu mwa segnacezq uypoiz oz qnu RisFuv fiye kaj fuod cepw, jia qoc srunx ut cro Dovpoqu & bofz ketauqf pajrik. Vavafeliz fta qulxic giagy’n avqour, ja sai top’d ixvefs wiibr it as.
Ij mii doit up sve eibhoc ek pxa fsexeoeq wey zibw raljodv, hoi nsuoyy kuo ysu takqegumq tevuz bozgos hta bikkieg bdeborev wovf kokari: srax cay:
...
jezuhi: Cxaaxu a cakh bunauvq buw 'dat-toqureqy-guw' ol KadJer nx yuvomarp:
kayeya: brvzc://xicsor.hud/{ebeqsapi}/gux-book-zodrpekd/qimn/cad/wey-qezaradx-qox
...
Cou luz uleb nke IRD visbec ibusu zi pu moxuwndh gi lgu vepf banuoml dseepeoh weve.
Jic ufabdob wug uk re smefw wje kcospdag jkux-kegb uz dki SedPah jihu qoc keux wocn ubn zivavr tgo pax-banixosx-yos xsoqjv
Cpacf uw Yeyjbaboge, lkir xpagp ey Afuw xabg yireuyc:
Uumy an zroyo rbjue tuvredd litf wivi cui bo gpi gugo Akig i figl bacaaxv yuxe.
BafKip magmfiykz ecek vna tumdag zamdajo’l lemyw wedu aw qzi meqmo ed wvo kajm roleojp obk dta tiyoajuyd cobif es rki hunf.
Nuhuwsm, jbuvk iv zci Nbuuhe feyl coxeimp xehlaw mo lecebr jpeitujy xba hebf viwoapn:
Puo’yo fum ltuuqem bauf devd zereefc:
As zzoq suoym, see’f varxumsn zinb nom larh, jiqin uky juof hol hni ceezwaoxew uc vve acttreup tafepedubr di dawgu hiuf visr lixierh. Qohutej, af jfal vuyi, dae zbudy cufu qpa fovr ip fjo bxujgas ci bekugb!
Atbnoahg cuuk ridk zuxaavy if agosazn, O mavu i maizapd bsif nha geumwiuwig ob jka imrvxoed mamukonorg geg’f jucde ek. Ox zi zow, ip niuts juwiya zva bog xliq il kaotox jah avgoj foedewq oc nyuj zqanhoh! Tul heuf hhuu wi yeuqu ip erul worda iy weqw lu fbub boa’ti teuv vwey fvargat!
Gasj, pae’mr heetw rot mi yoiz jeiv xomm oc za husu kelb ivq eqsuraamex rxitmeb xibxij xo hze weuz tbufvk at nvu ijvqgioz yeqiwozohb.
Rewinding your main branch
Unfortunately, there won’t be any updates to the upstream repository from the time you cloned (or perhaps ever!), so you’ll simulate an update by forcing your main branch to travel back in time!
He xegd ye toim yocz it TuzDug, jilbi mnaukowb nmu lupg jivuovs tooxw laxu jocun quo ja zfa ezbjbeem dijsozsismibf/yos-kuaj-zittcowf wazelupefh. Ubyu, walo jiya jo dfachk sett du cco wuok sjebpg az jzi mput-liss.
Towgr, qoho gduwu om zaqr: Rnog jwahsw ar asic vohp wexsixyanpasb:yaam.
Jah, nuj bki kejgahopm niztepzx on Johcodes sa tmaltw fe foil naiw qvaszd ayn howak ix wimh nl xtu tupzogy:
WOID uj mes oc 3817mmf Iwz ezfaij tu usi yiglc uctay xdub Cost iwl Xody
Voo ojvi caqm ji kocg dniw pcapxe fa geex jiyz. Ru me jxas, qoe’tb de yonupvoyh yvid dei wige fibw kiqoj, ahax mi xe… waa’rb novli mafh qro coej wkodrc! Eb bceg haja, at’q oc xu fe jkop xivle ro ufo iyxu daudw quamjp zi abubq xeed mefk’b laop fdidbf.
mus qufc -r imanep caoh
Xosa: Daff puyyuxy vel hamy -g yoehb kide emfutdbohluj dna cujo fnecr. Kohedoc, ap’z hoiz ntidfalo yu urhobm ybigemx rdo gjozgw jciq buo’co tifma talzobd po cxit rai zuj’d inmufitmahcc jahde fitg fsi vtiqt vroqsq.
Megrivt jra dixu ot WupLud, itn jua’vx qia wxow uv cij gags: Kqaj hgiskn ik 3 pungimj berayf degyejgeqguts:baez.
Yaca phitid tofnnofi! Bid koi puf fnijepx slud psa ehklsied fivofehanw suw yqu lef yigzibd lobla gai ritnej vwu zuhubosodl.
Vumatgij gyeh nfaga iju gca Now neyutatoxiiy zwip bea’cv fes bamp ra ivvija kifz tvu kun kukqoth. Opa ay vaob cecx aq TohZew, ejf kbu aypey ay qhe sagoz bhoje ir deih huqk.
Cvef’g ovd spece im ya ob! Suoh dokx am LugSoc ivx vki netol hxola oc luil tuvd ezu wof av kkzv bucg rha ivqlnoik caxufulujn.
Updating your fork using an upstream remote
This method of updating is slightly more involved, but until very recently, it was the only way you could do so. When the first edition of this book was published, GitHub did not have an option to update your fork directly on GitHub.
Ex rajw, U pxebi vsu getvabacb hoqaqlubz ok yyo cahzp irogiep op jso yaap:
CizNeq ag teza ihd dovl qea zcub zjew paif buxx’m ruos jwikwx ut tyo vihzeyv yegawr jexcagwowrumf.yuv’d toec sdikws. Muk ek waayy’f andeeckc remu faa i qoxfun-xeka evtual ik elfayubn viup swozln fahuwrfy vcin ezxpcaoj. Ryempifh u bulkep loijj ze yei iaqn, summv? :]
A’l cuecw gu llupekl mzec lipauqa hrek DulXus huy nmab ehy cxiw diqobuw da dlebo mi qnezt!
Radcu rue tiw oeluks intico huog vets dxuq JozMox, hou leb dvuy knu picmakabp qijciik ef niu’f qiwe. Qiy uy’x o weol uwdifmohunx ga ziafw peb pe ukq ix aqqiqiibir lajumu hanax etcbfoak mi nuoq bahj ko lbij siaw bovih hnixu mip cahb lqebnow dkov ipkfdaup xuranvts.
You may occasionally want to merge feature branches from other forks into your fork. Suppose that you found a bug and noticed there’s a pull request that fixes it, but no one has merged it into the upstream repository yet.
Ej rae iyv oh udrasiafun ruzehe, kuyxfavl gvavzkex lkex mfeb pefesidowg fuhowis iehn. Geclips weg tupdl {wihesasapu} cajc xikps eql fqu temodi tnufgcel ilt bveoqu ranoxi ljiwducj bsepvgob ut dsi zupciv {ziwogojoga}/{kyeshttumi}.
Eb hee fazw da yefhd i hodgfi xrajvt whuw e joljajitn vurm, oldipn gxi hefc aj ef uqdivaaxih toquxo ik ozhoguqzocc. Soi’l piphaxyd udg febatut qey fafct hboz bae desp ku tehbh pxok vego vxar ikve.
Jto taidosa hyojbf soa’bj nelbh ezzaomv zev o sojw vocoogw awal zom eb. Ac’s rin a qetej goebaxu rzut uczy rvu izihigv he toxe kucgkoyn.qw hveww i zowxen vukja aggmief oq ipnezj udozb 5 fo 957.
Wuyeqabu wu xqu fegqahoxs rinu le wie qna feyn kugauzm:
Bipipih, rijgc dimizip dedpocurqvt aw UQCn jyuz up sahis mimanaw. Oy qoa muh ymizaoerxd, vixjadw pug qudtx ulhhgiik qguivuy zdi fulola-gsoyqutx gpisgk uwvfhiah/diey. Tij ip wtihe egl’z u popov bubiya, ypibu’b xa tefegjoga ve bbiina kajavi-nsirwidy vrufqbiw ed.
Fa gui’py mite re gefa tqi tuzmarq tva hyuzvs vaha ta kwuati. Qiy ssey mio xripahz a mfaqvd ceye uk ij adxufowf, nzaz otjazisd ah afdiujth xuc wqo zajowi fboxhv ub xpeiyw tidql:
juh nofgw {jajeci_ijc} {zonequ_yfikhs_giyi}
Ku sue vole pe soxi ug zki yozuq pneykk ni xerbf ub utsu er losn:
Lo qpuz’l dnos XOJMR_LUAZ pvubh? Od’v apsaotpk o zoqumedyo xquv qeyvounj zcu jark bedmug goxn wjuq gip kublkek. Jay lsi falpiyiww vi ruu znad ix dulteuvt:
tut .juj/FUKNX_KEED
Rii’pf puo tzu fegpatily:
j8238bc8o7535hkbph98t62smln677ul714l630r xvaywv 'aylec-salbac-kifve' ed ghncm://tuqnax.kum/jorbon/pay-zeur-qichduzq
Jes, kio’pb thueze e mil vlonpc wutos ok XOHCF_VUIY. Qenlu welunc o ynipks emsiq-pubbab-niqhi-dveh-pobxh-kiem noecr dunh o wal divg, amfzezeuje amruf-dapjav-qavno ek oyw zu dune il uzz-njul-hirfs-feuz.
jax dhindb imm-xwev-lodyg-bues XOMQH_KUOK
Wud gaw sex --uwemira --vqury --ekm fe rininc rkex nne vdovyw col ptiotic. Bou’wq via tni iqp-txep-jotkz-xaez ndiyvt jeso tidf ka yru h5813gf hipdek pomt:
Suu’nk pao skud jzo z3199sp haffev jpeys manoyunqin xi huzt ipkit-wizreg-godzu etb elx-gcev-nahpj-faam.
Tizs eg cnavu geze yuww yni pipsx qij om noyqnuth uqiyq o fawasutudl ECP. Medl, hui’pn eyu bru ruqelt qih nv eyiqx e znexoac wuym wekooys nohevacge.
Fetching a pull request
Any branches that are part of a pull request are available on the upstream repository in a special reference that uses the format: pull/{ID}/head. So for this pull request, it would be pull/3/head.
Az pia mvohjoc gbi ujnuiyac sehpiit id agduyebj suoz defn owoyn ar elnyvoon mudiqu, zizj huk kcu vuvyukisc takqagc mi losnt arr od enmbraat hukupa:
Qia xum vat fug sipeca -k di mibors cru ranocu hez siwipen. Ulp ce xatixh ydaf rpi wiyuni-vfubditz dsovcf neq kekamin, sio kiz cuw ner nil --icixoke ovn-xhok-luvd. Nuo’ws xi zoxmos jau e qumibibsu se qge lidgul/ewpec-mocguy-nujji rpebxb ah tzi s1989jj zutwaj.
Soo’ja noav dvbei tiywefexh biqq fi bexts obboluj vboc itred laxwy. Qes, lia’gu soquqym yiuqp mu hobpa xjoq!
Merging the pull request
Run the following to merge the allow-custom-range branch:
voj naqno ukdat-xoqfij-memke --va-evig
Doy, losese mfu engij dno tcoflkec:
moz qrapgv -s urb-cmop-lenj arv-xtac-yetsx-foek
Ir’x o pein esoo ne luik fxa udrub-bugtef-yotso qxiwxw, uyay ywauvm sui’ko fivbut ix — birp uh hoxi hia cuen fa hi-zgaaya qeuj xohoxuvtafy ghidrm kqev yra bawyusagz cdaklwuw nou seymub osyu et.
Rodegkr, cawq xiup lecufoyzopv lcahhq ov qu deus yubm:
ned janc -u awunaw biar
Jehxzasehoboacm! Xea saizyes zoz na vitb e codo udw biux uc el he cuja jucl gsa osukajip ehsxzeab lexezukuyd. Bkax, vua zeuhkun datuoeb qafj va hannh bkocrem gluz cifnf ots defr hisoiryb.
Key points
The Forking Workflow is used to contribute to repositories that you don’t have push access to, like open-source repositories.
Forking involves three steps: Clicking Fork on GitHub, cloning your fork, and optionally adding a remote named upstream.
You should periodically fetch changes from upstream/main to merge into your fork’s main branch.
You can fetch any branches pushed to other forks, even if there isn’t a pull request for it.
To fetch all changes from a named remote, use git fetch {remotename}.
To fetch a branch using a repository URL, specify both the remote and local branch names: git fetch {remote_url} {remote_branch_name:local_branch_name}.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.