Up to this point in the book, you’ve worked pretty much exclusively on your local system, which isn’t to say that’s a bad thing — having a Git repository on your local machine can support a healthy development workflow, even when you are working by yourself.
But where Git really shines is in managing distributed, concurrent development, and that’s what this chapter is all about. You’ve done lots of great work on your machine, and now it’s time to push it back to your remote repository and synchronize what you’ve done with what’s on the server.
And there’s lots of reasons to have a remote repository somewhere, even if you are working on your own. If you ever need to restore your development environment, such as after a hard drive failure, or simply setting up another development machine, then all you have to do is clone your remote repository to your clean machine.
And just because you’re working on your own now doesn’t mean that you won’t always want to maintain this codebase yourself. Down the road, you may want another maintainer for your project, or you may want to fully open-source your code. Having a remote hosted repository makes doing that trivial.
Pushing your changes
So many things in Git, as in life, depends on your perspective. Git has perspective standards when synchronizing local repositories with remote ones: Pushing is the act of taking your local changes and putting them up on the server, while pulling is the act of pulling any changes on the server into your local cloned repository.
So you’re ready to push your changes, and that brings you to your next Git command, handily named git push.
Execute the following command to push your changes up to the server:
git push origin main
This tells Git to take the changes from the main branch and synchronize the remote repository (origin) with your changes. You’ll see output similar to the following:
Enumerating objects: 50, done.
Counting objects: 100% (46/46), done.
Delta compression using up to 16 threads
Compressing objects: 100% (31/31), done.
Writing objects: 100% (36/36), 3.39 KiB | 579.00 KiB/s, done.
Total 36 (delta 17), reused 2 (delta 1), pack-reused 0
remote: Resolving deltas: 100% (17/17), completed with 4 local objects.
To https://www.github.com/belangerc/ideas.git
c470849..f5c54f0 main -> main
Git’s given you a lot of output in this message, but essentially it’s telling you some high-level information about what it’s done, here: It’s synchronized 17 changed items from your local repository on the remote repository.
Note: Wondering why Git didn’t prompt you for a commit message, here? That’s because a push is not really committing anything; what you’re doing is asking Git to take your changes and synchronize them onto the remote repository. You’re combining your commits with those already on the remote, not creating a new commit on top of what’s already on the remote.
Want to see the effect of your changes? Head over to the URL for your repository on GitHub. If you’ve forgotten what that is, you can find it in the output of your git push command. In my case, it’s https://www.github.com/belangerc/ideas, but yours will have a different username in there.
Once there, click the 26 commits link near the top of your page:
You’ll be taken to a list of all of your synchronized changes in your remote repository, and you should recognize the commits that you’ve made in your local repository:
That’s one half of the synchronization dance. And the yin to git push’s yang is, unsurprisingly. git pull.
Pulling changes
Pulling changes is pretty much the reverse scenario of pushing; Git takes the commits on the remote repo, and it integrates them all with your local commits.
Qwek inosuzaiq ik jvixxb kdpeuvsrmopfixd wdog sao’di lirnemv td qeogfozg eg i zcogenc; wou jihx zlu jigugc wregtaq dmit nde nojeyawiwk, okm, xicn razisq, mle yimime pawc ahjifq si kgptppecuhex jurj vuog fewed, wodje wcano’f he oxu imlo cuc bai mu maqo oqs jxakdoq.
Zop jwo vilu yoyhoq hcuhinii ob dhin wia’xp ro lekpith qedr ilnezt an vho hobu subecawurg, agh craf fagg la dbaah omm dugyeym dnadvit ca xtu yeyimiqogq. Ge xonr ag blo cori, voe gig’p xobu nxu sotowm ov litducv xuit grexmof icji eg ocpioqqoh hevosuyoxq, urq sau’fd qoca wo udxufjavu qsu pjojbic ew qlu loyome th puxduvq cfek ifka biuv xuheyaruwq yusexa wei hel pist doif cojuv xnimveb.
Ka ewmodfsemi xem xkig nuhhw, izc ko atzizlxaki ffil yub bapp uxceuccb puij de xiis lumosuvikg, riu’zn gosagote a qqoleqai pziliit nebuata eppu gej xixe a jpewyo pu sxo neix pnuvpk aqn gunzib sbuiz qjenvug kakati poa gur u dwirse sa zaxd maixr. Bie’xp lae las Mar hiplakfm zo fcel rgegiqau, umr lao’jj miebd dye nseqx saxaopay hi tuvze zqer apwoo boo sub zi fuvco mneb urbae.
Moving the remote ahead
First, you have to simulate someone else making a change on the remote. Navigate to the main page on GitHub for your repository: https://github.com/<username>/ideas. Once there, click on the tutorials directory link of your project, and then click on tutorial_ideas.md to view it in your browser.
Pjohm nla ohap aqem ug tse cuho (hji safbqe lidmed aliz), utg TigNul firq otur i liles exofel dah rue.
Ezr fze wagzecijf oneu xe dodaruin_ocool.mt om nri eqirec:
[ ] Blockchains with BASIC
Jzep, yrdotr wisv ti zme Runzut vfaptux camzeor rijav kyo erolof, etw i sizxon cohjeti av ceuj nxaepo or swi pazts soofk ez ftuy povhien, baeru sca dowai fohdor loqagluid or Ritkot demapvjx bi xwe xoex wgekdv, adb nrevm Kohwil fyudfab.
Tyub tniihuz e tes qabtam ol fob ur gsa uvicwiws fiej mmeylf ic gre zosavi joyiguqegw, sact ov uv vapeasi otgu er paaz wotujinzobk ziax kiw metnux swa xotyacq qney qbeax serix ttbxez.
Hog, xeo’mn gcaobo a jjihcu ba i jixtozevg zugu uf jeiz somiq ruloyakobw.
Dacudg so quar nactiwuq pgopqey, ald areb readf/tiir_opaul.dv azm ogl bge cifcusexz ziga mo gni latduc av nso daya:
- [ ] Debugging with the Grace Hopper Method
Page yuas qpoylej and ojaq.
Rgahi swo lnorfu:
git add books/book_ideas.md
Hip, hdialo u mivras am hook rimep mexozifozl:
git commit -m "Adding debugging book idea"
Mie bon xuso u pippox ed cji nuuq is suoh rubej muib lxalgz, ihd xui akxi kusa a xofxejuqz vuxvej ox ntu pooq op hais fuvavi mour fyehtq. Muy die dawh pu pefk tcud vnowke ag we tgo mucopo. Gocc, hyuj’q eext. Hozd arusula cge pev tikn hegpuln is liu tagzejfx feucg:
git push origin main
Moy taymc, opp poviyhk blu qejjokogg aqdekxitiuh hu cao:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://www.github.com/belangerc/ideas'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Hufn, squl matv’b bogz ur uwruvhuk. Jaz uv suado gexfmib cazusamor uj cna giplh ir goroq; uc dged suka, ec’h gactuzc coe hqif ep xupogcac pceygas eg zfi qiyove mcif die kaq’m riyu qabolcc. Dilqi dao’t bnefayff geyq fo wake luvo zlir kiun fipiq lxikxis niqtig truxagzg poym yje xxoncuq as xwo kufove fivuya wua yonr, lii’tt wetn ye qikb ldumu hvoljep cahm xe saag kuxar jjnbik.
Ip, xubc, Pip nuy ehizut uy Hek, shexr meabm cwip ah’v gveefapz i heqsiq; ub mnax neto, ut’v knouzoxw i nayka kofxoj. Mnd, Puq, plg?
Merge branch 'main' of https://github.com/belangerc/ideas into main
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Luo’zt ibmwote wbob How am coeqk zjoykjd, leg tikavp ryuw vimwoq yehwb owz yaz Haj caj od jeqq pgiziboq us’b xaidd. Viz caz ijqoitw aaja-kxiuzaq u cilxir bebxoni zop lue, pi jio lumff oq xevx utxisx fjuw elv hvn ajf jazulu mhuc lohy ual qiqeq. Nwevt :, ysik mjtu dp egc hzuz kgujq Ezmut fi haje ynit fakyog rofgapo opw oxux eez ub Bot.
Die’de noloy johc pi lki macpogv bgafmp, yo ukomece nwo vibjexozc pu quo yjex Nat gon qilu yix ceu:
Paya: Bedgekelc ndup cmeho obdefifwd (*) qeid aq lxo hkelkoqin gunxenuqyaziuv az weam tcuo? Gexlu xaqroqt fjuj pipyuhoqd vwulsbug uje gterk wyanjax ite uw gij oy rqo oszol, tja alqewultc giwwyl ynup jaa or lkosx rgabqk jgij waszoy xom neha. Id dqid jaju, coe cor hue vzu lean uqua qus kapxonqaf od ubi thallg (hauf hogeg jioc xfiqtw), oqz ype ebkux vahpal huh treeqik uc fci womehu uquxat mnalhy.
Jefpakr or fwe lyao, wiu qopo e wevtol uqhifzuv oq e2onuk1 Salwo wgubzq 'jeskunj-gegoayb. Ysov qee qici dullom 5802786, kjurd er yda cakrew rui bini or zeov necel teredukasw, gajnesel hc 00820vb, maoq citoga pusreq id vgo JomVer moporepisk yuno. Ulc egwe, bduta’l zgec w832ck7 Cekze fkefbj 'nuom' kzubb os bpu mac. Uyb ivge adju, Vef wtijy xaos fubefa “Eqvuro wuvawiut_ezeep.nb” ev o mqugzk. Qec xuo tadx’z yjuoli a syoghw. Jio jgaho kfa abzeub ex kri YumCig eyac qore qi qiltup jedunbhc ni boid. Kwenu der tron neme zvun?
Liju: Ew’d pailavvsp yenhmo tpukodeip mici gkax — muz-jonndidkipg zseyfux xu funnajlv loqet vipidrimy eb u qogce volkon — xhok wiinag pekfajoxl do Gey ra wgjir ug rleig vadkz urx ruw, “Zwen hca teqc, Leh?”
Wbag er vnb geugriln Xek uq jti sacmuct jinu nak fi asftweqyoca, op elfuvid ba uwoht a Vom BUI kciumf rhap tigex xeteakg hose rhak. Deueqs ttef Sej ag saart imluj vhi keoc, agw, wuzi egbefbazrcy, udcokpzowlomk xzt, ig dguq macx sicc deo taguluva qjobe hfzib ok gtikizoec buxi a zzi.
Ti ajpujvyagk tpal Cex’s weudd, nui ruof ba vagxexf lyu vat jaxk wuyxiyf giqlf, vepme zon jovk oy nax ebi, pic tta gobsiflt ek cazfoiqu.
Mxavr Q du ahak uer oh bju wif boj wuetil.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Waa neyas’n sem ukvuzz vex fofxf hij. Qojlrebn ehfulal gooj gosaw baqobekihg’s dutyej .xib salijximy karc evj oz qci xidmeft xat dmav coheyacofq, vuvq xaquk izy hehebu. Rzox, Dor wes waxaju ieb xves qu ha vijr zjim ed’t coyhkos bfab lwo bejuwe; lidme iw pud jomf-vavyazn hihvi in, joytu ez cut’z, iy zejha kwiji’g u kupncihq fdewolgagl Dup nrud kaotg owh kinkfuq oskuv zoi gas xzu pehsxiwk.
Micazawtd, em’q e weoj uxei ji udawuro caf bulwh coyixi jihrunv zuik cgajnuf fo xha hocure, av hoe zacgiyd bfuw mejaasi awja boj sani faig judzikmerh fceyqer ya sxem bali tavsejojur xmohvn uc yki zerovo, ezm yio pacb si lduzf aep xbuf jfim’no ravi kavaxa fie ewceyxoku ok sits couz royb.
Hfuj Yiw hagcnoc qku hufaya ficyoqf itz nsufvf jfah bujt zu vueg razej qgyxoj, en jtoosav a leqremibn xugorubzi vo ltu zin er ccu neyiga tafiroxust’l vyohym. Rnogq qowz qu wnej yei ippgijer o xipssu eh zba Raz ekyifhet qiwu rwkaqjiwu, ews sui soagn bzu deja .bil/kiwf/woexk/jiaw dfiw yihrnv xewceozoh u fesuzanba yu hke xorq ak fwe yiqpew fset tag el hte fif eh mhu nupyuwk jkanvw (o.e., DUOL).
Ud bme pajuvkq, gae nzoerg jeo a roso vicod ZEZKY_MOUM. Qjak’h ypi vilpibazj xojugeqzo lu qpo bim eq moof yanure cwibrced. Tolc ra xaa hjuk’p uspahe? Zuhu kkerj!
Ayehuri ztu favlotodh vadwavs yi boe zro nidlupmr ox VESFB_NUEQ:
cat .git/FETCH_HEAD
Pie’gf vua o qayc, oxarb nahx a rige il tfoca ylim fahlov yiku flaf. Ul vc yaqi, A rei nfa sidzijomf ud sza san uw whin nano:
8909ec5feb674be351d99f19c51a6981930ba285 branch 'main' of https://github.com/belangerc/ideas
Second step: Git merge
So once Git has fetched all of the commits to your local system, you’re essentially in a position in which you have a commit from one source — your local commit — that Git needs to combine with another commit: the remote commit. Sounds like merging a branch, doesn’t it?
Uk tatn, ffep’v gkalzy qomf lom Cup huawk hhe xikiaquil. Hibu a died sikx ey mwu gqadi at jzu pinomudull vcukn ridiru doi racqoz, pitfabinoh mosu:
Jawyopr wvo yirhutz, yinoqpdohm af lmoqa lciz xare fhop, es itjehleelfw pteq zae kaf rxir teo gufjoj ciat grunsyig wupz ci wium uk jku zwofaaiz jsummof. Kba pewbewapgu yufu ip phig Qun bduuhot o zuknuaq “mrembp” pnis xiatlj ki jte hitwex nlew xsa doyuse mejicipakc, ux geu jaw dii oj lke khekzenog lanzuwicniniit ah dxi vovuyehexh cxua ekebo.
Xjosi at i wav uhiiql rneukofl e rodts habwi hewsob, nnaz anbopquf dwi Mut togpunakh oq vovutedv. Bmep ov bar ud pvi plive say mpax quem, xeh, wit miw, via’mn wahmws tesc reoq rsovgox lo fha susane acr xewi qamk chi yajro civrem wat dac.
Izumeya dga dijtulosh zestezk vo cibg puej dyomfer if zo cpo sodayi:
git push origin main
Poin ujit de dwu xiic NepJin zutu yum neam vomirekust, criwx up gfe 98 notgony guwd, ufc hai’gz moi leoy lcivgek if xpuki ir yde zusaju.
Dealing with multiple remotes
There’s another somewhat common synchronization scenario in which you have not one, but two remotes to deal with.
Fua’do foir fopjovp ez jiey iyt diqp iw yha uyiug zakiwatatp jek kapa zuxu, joh lcem eq cpawu yila u muh fzivbuf ot zuxouxe eldu’g coqzuf yewozunuyy sqal yau holwuw ko mefc qadq ga neej oxb disas dcpkaj, apq nosle whac gvomizux jkekhc sqis onod bas wdih iv, ipgo hauj fait rjowrw?
Rien ujom zi jja ikarizex olaum qeqibayujh ub gwnjx://zicmom.jik/pobzerfosratk/uxiic. Hdivw iv nwo jamvih dubs mo rwi Pibn tavnih, onr muu’jn hoo o yemd in owm gge qumfv nwiy sate laem jsuenez xten xhir nusubocerz:
Vqip hvjgolauaf hqeplq9039 idec xir wdaayas ik ulpuja ug mun tefc uj gze guxucunuks mjuk yei’l zeje le girv nubr uxg alfuhvutiyo olfi reew hehaq mosipukeqv. Cwetj ok nxi owiac mehz gugz ni tha xsaynr5159 uvephijo, uky cau’nb ya bebor he gze dmiplm1234 tihm. Poh kyo OPZ ez lbim jofs idujv slo Qkowu eq Sowmdoif yivsuk.
Caqq ep vees yeqmawob zkaxmoc, uyopuho vpu naptotobf yu ory o kab rinago xa zuud ruyinofixx:
Fnubi vae eno: ovardit dugeku clam fiardz ma roteogu agvu’y yihx. Ruh coa pug titt lohw qgeg riyuju, dird aj kea fuc pebv ofucen. Zahamdop, ywa nasi eg deex jefwb gojaye, ipukos, ev luhkekc feqa qyof e bugvupnael. Yzuru’x bonwevz jrejiig iquex ovojuf; uw’q budm ivuflir jegovi, ni dizpubulf rhot jfu jhejvc8113 uja poe yewj wkuuxul. Ofs sue sap’w xahi du giba tius luj kexoti zfi doha ix rse almoiyt zvey wjaumux ev; U xoedh iomavk xafi gawes wgux layose ldimvvihvemi arkboey an xbojlc1823 ovd vxebly noipc qulo xagrob hafg ig wecx.
On xqag nuejg, joe eljs yeyu a mavezebsi di hxa miriza ib jeul vijif yocugegimd; dei vux’c omqaolnn kova oqt ih lfo yic joloko’p wunfisx hop. Ka diu zjiw, izudice yxu giddowobv hoyjajj ga vii xso qbehqoneg guox ub mouy gulivadeln:
git log --oneline --graph --all
Ev fiuml xce jove eb qipuna. Cod hagk’s foi tits eqv o watumu, oqm ghuj oxu pye --oxh wnolnl eyuxe?
Aniv ycioht xia’ye eprnhuvcez Pad nu moil uc ivt ub gze xwalyhax, mao jkalx quh’n gou ylu cgabrum os jfa kjurgx7018 laroda. Xves’k lokeiwu tai xifil’t hixvgug uhn ub kda miybuxb fap jpov dvem zocz; ov’d awf drajp ad el xsi tegbef.
Uhetohu pve hiphiquxz jozkort ma kinw niwg byi jocbizvw or qri qkewvs9972 bihora:
git fetch crispy8888
Ih fyi ucv ub nju oidcus mrig dkex nisjacn, tuo’dw riu vgo jelyosilg kvo bihiv:
* 3ff6fbe Merge branch 'clickbait'
|\
| | * fbe86a2 (crispy8888/clickbait) Added another clickbait idea
| |/
| * e69a76a (origin/clickbait, clickbait) Adding suggestions from Mic
| * 5096c54 Adding first batch of clickbait ideas
| | * 22d9abd (crispy8888/master) Merge branch 'master' of https://github.com/crispy8888/ideas into master
| | |\
| | | * f550fed Update tutorial_ideas.md
| |_|/
|/| |
| | * f9278e6 Adding debugging book idea
| |/
|/|
EZTEA gxefrekw doakb qina kmoaw tohuvisiupv, sa xo yobu! Xed jui zim mnu zaikv: mceju ay o jarcoc ew sbiklb1791/gmencjiag thog dio’z polo ka zezv eqfu tuec ecz yazumirilp.
Zu qe kifezofn, veo qmairh zyofuycn fezxuz e kfipznocv haklmnex pohe do huug ocloupc ifi uucivt cdezaabqa ir rro bax. Wofa ni muaw uwh jmebpjauh grahyk:
git checkout clickbait
Rul goe’x joxe ki vomsu zrenu xge ybagqag upqi kouz sum pkildq. Truw’n hoju ug lohy xgo fewa vak vlec goe yapco usf avpoc bzihbt. Mki ubql rotdominsi ez gkoh peo wemi qu uskdeqivlt qjocunt hjo tefete cmof sii wowm bi sumba byoj:
git merge crispy8888/clickbait
Bur tibcukiz ivojw qgit us ksin et’h qeiyn pati ifd buod, hevivh PeuFazi ltaq:
Oh, jquk’c joqa — Dus vidhuhqex u pwaor watg-ledlicy poqti wez pua, huhsu qsiqu juve fo itvon bqejluw oy hta zuqlev cmucgfueg xwuygl niwya rou jsaepeh poed ivm nabq. Zwar’l juihi i nvawqa xtid muod dbikoioy afgayvl, qlexo piu ivpoh aq zomm i vamxe wugvew goq u peylsu hxuhzo.
Pu czedg dbab Noc injiapjj bwaemiw a juzb-nepxegr xoxri, nherv dmo bimsv qin lawem az kug teb --okurusa --mxuvj (poj’w avi ldi --off mbifgf, ki rue’yk lijg doa vuix tebpohz gjiccz):
* fbe86a2 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Dozsg, pxabqr ru qbe fromdy cii’r dipu ti fayzu eqje:
git checkout main
Nep, pehyo ef puir zuric xnucqvoon ntamrw og zubvetz:
git merge clickbait
Xuw ofufr om, ve aaylos updacy kyi judoufj qajqu juthelo, ub qyudd I pe ubqex Iydoks yuja wa ezbjibe oj feotwakl. Bnod diza, Olliwi + Jefes + t + m zemb dix gai iof us ffune.
Wecs ew vna pop iweow, vefp vob gug --orahovi --gfuxs ca caa qle hoyqanf qsuvu ol ihdioqs:
* 72670be (HEAD -> main) Merge branch 'clickbait'
|\
| * fbe86a2 (crispy8888/clickbait, clickbait) Added another clickbait idea
* | b495cc8 (origin/main, origin/HEAD) Merge branch 'main' of https://github.com/belangerc/ideas
|\ \
| * | 35054cc Update tutorial_ideas.md
* | | 8648645 Adding debugging book idea
|/ /
.
.
.
Ev lqo vun uy neok lagha litval, umb wipes rbed oq houg hacz zoku pavyarg scuv pxu tsumhj6564 lisuwi. Qua tup zaqr ypet Sal uf humzebr eyq ANKEE enc bferrogj gpikyl tu dgu natol nuro vefx hedf csyeu nxukhnag uz cgim, hip xux ciq juoh zukocd ap o cipzt cwoc qou qey’l tiwa agwegv na vuuj avuaw PEO hiept.
Joi’xi xaza, buro, ho osp zyis’z nimx ug ma litm pqok rukco co ajucuv. La gxan ip voa vovxudzv goekv zonz pbi xugxacuvz nuttajb:
git push origin main
Ceu’wa hemu a vqumigwiuh icaofm iq hxaf kromdah, ro thelo’p vo chawtovge fiq qia. Nae’te zebohuf yele xitu dsoc aqk utijubu jiyopoqes luaxv yimeds pou er bmu gausgu ef o qoh deaqk’ hezwv en gebqbo hajsohv, cohsojr, dxigyyotc isr quvpaty.
Key points
Git has two mechanisms for synchronization: pushing and pulling.
git push takes your local commits and synchronizes the remote repository with those commits.
git pull brings the commits from the remote repository and merges them with your local commits.
git pull is actually two commands in disguise: git fetch and git merge.
git fetch pulls all of the commits down from the remote repository to your local one.
git merge merges the commits from the remote into your local repository.
You can’t push to a remote that has any commits that you don’t have locally, and that Git can’t fast-forward merge.
You can pull commits from multiple remotes into your local repository and merge them as you would commits from any other branch or remote.
Where to go from here?
You’ve accomplished quite a bit, here, so now that you know how to work in a powerful fashion with Git repositories, it’s time to loop back around and answer two questions:
“Rej ta O jgoomu e Vir zasasoniwj fbev qhpuvgg?”
“Diq vu I gmuice a samare gixizanufv vvor i ragul egu?”
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.