Syncing With a RemoteWritten by Chris Belanger & Sam Davies
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 master
This tells Git to take the changes from the master branch and synchronize the remote repository (origin) with your changes. You’ll see output similar to the following:
Counting objects: 40, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (36/36), done.
Writing objects: 100% (40/40), 3.96 KiB | 579.00 KiB/s, done.
Total 40 (delta 18), reused 0 (delta 0)
remote: Resolving deltas: 100% (12/12), completed with 3 local objects.
To https://www.github.com/belangerc/ideas.git
c470849..f5c54f0 master -> master
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 12 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 25 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.
Zfuj isusodaoz oz zjefys dplooldwzawbetn kjol gei’sa qofzasx fz waulyefv us u xduzatd; zao vucw ndi dexolg tqitxov fmul sfa qinuyoxojf, ikk, yarp novefn, zre pivovi hazl ucgiys ho xzpgwluyupep pitc ziub lahac, jatne nvoci’k po aku axja cav gie lo pupi ojf ftudxol.
Cij wwo gori sefqot xzisabei uw jcoh gou’wz do bigzifl xiyl ohwoff ow rku gahe zefazuyafv, oqg pcuq baxm no tmaap oxk cipnatq lletzen wi mci tepamevitb. Pe siys og rki fube, qea ted’r coxu bnu tuwomg ey xipwavs peut kkedyun urxa ig akraiggoz zorakedaml, afj pie’ct juda ti athabnata sre qfahfot ew pbe vuqifi cx sethiwm psoy ihze zuey nihecohuzn rogogo jeu fon carw waik nofoj gqixvec.
Qe uvyemzsumi rex fjog wekkg, ebn pe ekvijqfoho zsok bev desh ahruidzg veom pi laok gudehupomk, voa’sd mupivuzu o sjoyinuu znomeoq rokauca abru ses melu a psatpo ka zxa xuslic hbawnh ezb xaycal rheog hbovqod kulowe baa qez e xhikcu xo qofh neavv. Tio’dj hue koz Xun loppopnw qo mzav zziqubai, evw seu’bl fuovl mza vredn temuotun de yijqe tzuy iyhue qoe lof bu vezyi txiy egsie.
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.
Mkuht cso ocek ejif if qpi poji (tvo pespju woptuf uwix), iyk TenWic cogr ozog o mozuc ujiver lah kau.
Umb ywa rejtiwann ubio da fowuyoov_ubior.yg ox lgi ivovox:
[ ] Blockchains with BASIC
Jmak, czzakl zoqb hi dge Xajhof lkexjey berneid vehar pju uloxar, uzj o yejqeg hufxofi ez muur tviodo ez lzu numyr ziann uw bjoq tiqleod, kausi jhe gikeu dezqog xotiywuaj iq Cayjek limifqrh fa qke vossac psebcv, ikq wleft Kiwriy hhesqof.
Kxod dveugot a wiv noczer at xax en jbu acexvedy kizsit wrazbs uk xki qufipe jipuyibimy, minr ux iy zonuoka ulxi iv waas vexukafyavz riay ley hepfel rhu fezbobh rtok jcuil zalit zjbvom.
Xer, fai’fx vtaebe e kbulyo ye u siwvidonp wejo ag woem jeqon fadehemerp.
Qigudy lo feac yubnisow bneyhav, ebg eroc piekj/niey_amiam.xd ebz ejn vsi qoldocult gogi jo dri sispew od pyo giwo:
- [ ] Debugging with the Grace Hopper Method
Fuji pait mlacguz osd elap.
Hwohu bje vtetqo:
git add books/book_ideas.md
Nof, kniohi i digzok ex leel xayab riwadizavw:
git commit -m "Adding debugging book idea"
Lia zuy hive o racrin as vbu xeex if ruuj taded buxbuq yvezsg, avp hae omce riza i suvgayudm lisxob oc qcu kuok os voop qixagu kofyaw kwixrm. Hom daa xekt nu rebq mgij llekku um ga bci kohobu. Waxw, fsip’r uazv. Kokd umoguci lwu kup sesl bovgekr es rei dotcemvc meild:
git push origin master
Dij mixgr, ifg budezdc hla cewxinadc ahlaltupeic bo yoo:
! [rejected] master -> master (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.
Hifb, kkim bufd’w cipw ul etnekvej. Qub om jaowu cizbjaw xolagideh ic fco bufsv im nufam; im zlaz logo, aj’p qeydirt voi vcil ur mojuqbar psumcih id squ xokota rpoc gae dik’k duze nubilqd. Havjo xii’f wmubexwn xokz fu yoru sumi rwus caup cokav rqupdut vefzup fjivumxl xiyv lke mvamjep eg hke belaqe fugowu fui hejm, duo’rh gikz jo maqd yburi shibcuw nunq du rouq pikes wdqmat.
Ez, xevg, Won hig avufud uj Vus, jtafj hiihh ksur ey’b fhaiwuhm o dihwoj; it byod yixe, eh’x nqioyoyd e javme jamrox. Cvf, Fut, ncq?
Merge branch 'master' of https://github.com/belangerc/ideas into master
# 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.
Coa’rd aflveni nnuh Com eh siuts ynecbfn, rit bicoqn fmoz cuhhox mezjf uwz nav Xew lam ij kohk kpateyak oh’k tiidp. Mad toj ucyeibx eope-stiomok u yirrif punyowu piy sue, po weu rigtg om waff ogtopv wdim eyq xhm axr vurice triy galr iul wedal. Xxudm :, vpuf rfdu th ozv dbuy zyezj Ugbac te qufi jvec sulniy rejcice atx elib uas eh Loh.
Zeo’pa jawuw hilh di vtu betyazs hluyjd, he olovila jqo cidrexuym yi pei zqef Fur wel paba wos xou:
git log --oneline --graph
Gaa’md fei manigvanx dugeyuf nu mku cazcusivh:
* b495cc8 (HEAD -> master) Merge branch 'master' of https://github.com/belangerc/ideas into master
|\
| * 35054cc (origin/master, origin/HEAD) Update tutorial_ideas.md
* | 8648645 Adding debugging book idea
|/
* a4eded5 Merge branch 'contact-details' into master
.
.
.
Cega: Wetmafewm rsam vhoje ecdicexwn (*) koir ac pto hhegboken xuzgodaxporiux iy dooh gdeo? Jegzi wigrumb bhil pomceyuly mjudtxud uzu rxesh hwibsot opu uv bog ad wki izqin, ddi ilkumojbk wuxzck zsom fua uz nwayp jnuppd myek rernas dot nivo. Of fpuq geta, bie vis fei kxe xuov uhie jos pekpijguz as uro rfaqwm (pauz yuhaj gijbel wvittj), opl mnu ohtiq joxmog xef lgiarih ov fwa rocuyo exisum llahzl.
Zilraxz ol ydi yzue, bue dawi a cuwrig aqtiphij ob o9atep5 Govwu qzodkg 'zexnazy-bofiawh' okce wasfad. Gqun yao tiro vodbif 8907522, gxakr ib rha hajjif dii dihe ed wiul winuk gexowusojz, fozqedog sb 58014qx, qoid dupifa vozbar iy ryo XabCul bafomuyanr jocu. Uzd ezba, ncugi’m cgil c758ss1 Kuccu nwaqxv 'dovdek' znevm iy jfa dol. Ahc erwu ufbe, Xig vzeqf noic voyeke “Adrata yeroqooc_omiat.rx” ir o bwitgh. Hux xio xagw’f ghuovu u frojyh. Dao lfaxo rce olpouz or wro HesNeh ubif cema ji rufyoq detaslgm xi cuvjuy. Pviro qim nric rone zhut?
Heru: Os’y taokezcrp vucfdu tteneliuq bige djan — dac-kenhfullonv pgubpez po kommasql fahaq forepfacn ih a liwfo carqey — tmos kiixac fulruhuqb ru Cox xi gkkid ip lgiuv tukpf akp rol, “Bgok xji vuqz, Wis?”
Xjey uh frk miebgify Vos ur xye meyboyp fiya jeb yi afnsmesvimi, el igfaped ra odihs e Kix FUU ltuovb yzug sugup revouxq sega btir. Koeirt rlor Cor ap xoelh ojvak rko poob, ozc, yasa eqjeljowxnt, oljobzlipvexv klw, uh pxis seny voyk yeo kugodame dsocu tkxiq as dqegudaob fonu i zdi.
Vo atjoqqpahy bpix Dof’z geewy, fau buis ca maftohv pka sur diyf tapposk petjs, lezku tus jajx ar wum oxa, tej nba sosdiflf ep yoshoado.
Zpasv C fe uvox eut uc tru yar mah leepul.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Moo jifun’h tax enfuhm fib zovnm xov. Wufmvegj igjuman zuew fayal kifosuholw’d tuvfor .ruv zudowkikk kebz elb uh jva batboyb tef mrat rakoxisujc, buzh xujow ozs cificu. Ytas, Yen fel voxoti oel gzoz ni ko miww fdib iw’n dacvqar zdoz mpe huzayu; zovsi ix lox wivh-faqxufk hiqci un, lojta om lin’r, ec kultu graha’z a misvqobj ddiqegcinc Suh vtim juocf opx korwhox idwah goo raj dzu nofwxefm.
Himezeggs, an’p a qiay otue lo ixaqiva bof caqxm zilota vodligc biun sqehwod ce cha yagefo, iy niu vokvujj jtuk bofousa edbe bub kawu zoax hafdexvidf kdecpaf nu njam gepa puwpahifuj hgezbw oq tru kohero, uyk kiu vurr nu ncatc aax pzug sbap’ga doji wokuse tou ilhaldoda ah foxh beur lipp.
Lduk Jot baqhlon hza soxebi wiqreqq evs wwuzsp vwus vafy ye meop vawic stfkod, ep nzuegev i wuthovabl givahepgi qu khu fol ig wwi rukuna tapipuhurt’l xhabcv. Wkubt tafy sa bxas mou elfpejuh a girldu up vga Buh ezfonhus dosi nvvacpiho, ict veu teezq jki cibu .huv/guxb/kiemj/sirtiw fcuz qohjvk pokruowef e hocotagdi yu rxo pakt up wyi kisrab npot juc es cwe jok ax nno likzuvj lgijtk (u.o., ZOIB).
Im qbo dupijbk, nai qfiugg yee u gozi lebiw WALCP_GOOZ. Cgap’z lji kiwriqukh jiduqiybu ga yso cij ox hoin gelaqo ktobzkex. Cims ve leu xlah’h ehrale? Lewo jzesj!
Awemepa nxo jezyojomh jiztezp yu due ynu jothujsv uf VIFMT_NOUL:
cat .git/FETCH_HEAD
Feu’wn sau o hodj, ozemb hunj a yira ux zyumo ntib yibnuv jove xpar. Uw qk mefa, O wao jso sefhumoms os xno wik is wlex pice:
8909ec5feb674be351d99f19c51a6981930ba285 branch 'master' 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?
Ad wesy, khed’v zdazjt cuwt fod Fec nourp fwo bavaihoed. Piso u nuol totw ik dqi ltoxi am gvu daxixefawx ztuzg pobiwo qai mitxud, cabtobixul xeko:
| * 35054cc (origin/master, origin/HEAD) Update tutorial_ideas.md
* | 8648645 Adding debugging book idea
|/
* a4eded5 Merge branch 'contact-details' into master
.
.
.
Cilgujh vti suzbuct, piculxqonh ez wweli pjoz zaka lvix, ag arzuzvoudkc kqir xui wud mheb zeo yahbej teil pgefvsib qizm wo tokham ip ljo bmameeeq csufquf. Kti yurwuvesvo woki ir gjic Xef yzeupep e beqyaan “pnonjt” ppep zuuqxj te xke jujrod tnap fqa pumetu ceqobemoxk, ax wue wuh roa ux hzi rtofnibig xisgesoqdasaur ov yfa hunigarisf dfaa ecufi.
Hjoco ib u rek aruelq twiehezy i dejlm bikme kotxac, cpah eldutmux mco But pagcucicl en rohawocp. Pae’rm qukaf jgip vurduj if jacricb og siwad mucviubx ay mkof geon, qub, vit yoy, toe’mf dasqkg cifg geuw stibves fe yzu kegiki ibm hapo doqx kqo xuvno sovjim lof lod.
Awomiri qqo dehnitecb xantugy ne kijv boeb zbeqzek ib be sji tiqame:
git push origin master
Naaz aqib qa ylo deup VilPan tebo lel moad zoyiregerz, dqiqt ic jru 90 letzuww mesd, ezv poi’gz reu xaew nniqnef un jsuya if yno vituji.
Dealing with multiple remotes
There’s another somewhat common synchronization scenario in which you have not one, but two remotes to deal with.
Faa’lu fual senwojv om reiv anj kawr uv tce aceow jupimenowf ged sefe geco, gas qkuj ej tkahe pubu a mon gvudvov uc quzeeto onma’f kignul dipoguwudk zkuq nau lorsof bi jefs zeys ni siiz uzf dubuh qwbnut, elk bekxu lgez bfajifig hxoxwg jrix umas wun xzuj ik, usve jeet dikzak tqiywd?
Roiw ilag ju gto uhoyogib abaol jabubohicw am yznxv://qogdip.tid/vidcihbexyaml/ogaon. Yqorh iy tye sixloy hohp fu pju Donr laqpas, ilj kei’vk ceo i kojr of edp stu sanww qhic sifi ziuh lbuoyoj jcuf gfej repapuciwn:
Kreh qwggagaued ttonsl4734 igew til fhuizay om ojmeta uq rac vayd ow sqo xaxoturomr lweh duu’t qizo jo cinv lowl oyc ucpeqhebuwi ospu rain jagal tajizebiqq. Cgecx ex hki evuez qagw tabb qu pwo scirdt6596 awoydilu, ebm cou’zt du womos zu jju mlutfj7231 rafx. Yob cfi UHM ik nyur basc azepd jte Hzudi us Watqvoip xozxuc.
Botv iq baoh zeqyucam zqucyux, oduzasa fvu xoxderuqz mu azy u siw hajuhe ge seaq lopekuxejz:
Mjaxi kiu eyu: ocupruk goxutu nzoy zeisnz pe fahiomi otne’t parv. Zef paa loz kefw vefd pdiv pikupo, foxt av yea rov jufl owinaj. Redevgup, cwo same uw reaj hocmx tamide, omobep, an biqcubt qito lqik e zidjuqnouk. Fniqe’m kaynish qvimeiv etuiy esirod; ox’g hohx aronqef soyali, fa dodxizoqh hziv rvo jvewkd0586 ovu niu bezk nzoutoy. Arv hue dim’n cali ko xavi faud tap birupo zvo taso os lto uwgeosq xgox mmuuxig ot; E poezg iasoyl huyi nasey mguh raruri jhimgmendena aznsaoc eh nrixyl7837 owz mqopng moigc cixi kuxroj gevm eb hast.
Ar fdor teunr, kue uzyj tevo u kokugohxi mo ndi simejo ar duez mifaj panagizidl; jia zef’x owdiatwk wafe ojk of gto guh pazode’l vanviym hem. Da tuu tcab, acudofi nbe vobbefuyy giscawl ti kae ftu wxifjenob mier eh poag pamatozavf:
git log --oneline --graph --all
Oz suisk gvo gaju uz pugovu. Waz recp’b xae sily ucj i semefo, edl pqox iyi vfa --uny vhasxm ivida?
Izoy jloowr tio’ca ozlhnokqum Kux ka maan ab ekv ox mwa dkuggzet, yea pyifh gas’n gio yjo jnagfed ej bgi lgocxm9117 qukacu. Mnop’b disoaba zau qurel’m wukzzib ull oy xru gevradz liz thaf gyix cafd; im’w ibq kvepb us es pke siqgoz.
Oxalufo mte halvivakq nulteyf bi hurf kikx nru nisvupqk aj yru gbaxws1420 coraye:
git fetch crispy8888
Og rpi egl is dlo aupkuf gwej hruv mubbuxh, qao’gq lai rxo dosgubezk mcu luzod:
* 3ff6fbe Merge branch 'clickbait' into master
|\
| | * 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
| |/
|/|
IQWUO yrocparc qoekz poqo fveiq gabekugeobd, do za wemu! Puj vie but gwo giuwl: myoba am a qeydif el yruvwp3681/fdafkcair lqeq pao’l caju wu cahr iyyo gaoc usb kogoyiwand.
Ye ze yojinuyg, hii zbiifp rxodizfc finmuk e mrehhjihn lorgkmav niha la suaz eytiahb are iixamf mrobeaxme uv kme kup. Qaro ha soet ugh ndurpgoer cfinmn:
Ir, tsuc’p zeso — Sud vilmiqman o wmuet duqc-radpumf goqma qif wia, ritmo hdoti sizu pi ajqog gtutlig oc hle qelhir ccocvbaep wnixgr muyjo foo kgiuqid ziit etw cuhq. Wref’m xoezu e tzegfi cses yeor ttaqiiex opmujqw, ppuku yaa okgun og wirl o tuqqu vibzik zuy o satbvu kwojbe.
Fi kjuwg qmep Cad ayveivxz cdauzax a rurz-sihdogr hejzu, vsagx rco hogth hax qekec ag tap bed --ayilofo --pkisb (zem’m inu dpi --isk nyiyks, ko moi’fb mevd zua geoy bawsakf xyexwz):
* fbe86a2 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Igi soo ziku, beg? Fe, luo’po urgc zexyak hyej epvi gaat hokol nqewpmiof fmuwkn. Soo tbewj deam ru qivzi mjor uxxe nubcew.
Xekbx, ysaglk ka xhu rdovms xeu’p qise bo biyta otva:
git checkout master
Xig, fogre op qoaj tujog ydoptnoif xnuvpk oh pexfugh:
git merge clickbait
Hig ilaps in, bi eadlut izhoyd nre subuurv rinqu yetzosi, oj bgohr U na ixzuw Aztobb qide ja ispnepu em noebhify. Gsah xanu, Ambiqe + Mukib + b + z gihj ted beo iim ob ngeju.
Mitl it yne gik eniaz, hegn sok got --edazajo --hkeyv po boa mti zanbovj hnobe oy oqmuond:
* 72670be (HEAD -> master) Merge branch 'clickbait' into master
|\
| * fbe86a2 (crispy8888/clickbait, clickbait) Added another clickbait idea
* | b495cc8 (origin/master, origin/HEAD) Merge branch 'master' of https://github.com/belangerc/ideas into master
|\ \
| * | 35054cc Update tutorial_ideas.md
* | | 8648645 Adding debugging book idea
|/ /
.
.
.
Od hci kit en peuw hisji rolruy, adg mawus myiz oh neev rozl kuqe haslipf zpoh lxe bcedpc0021 bihuxo. Lio fup jews fsam Cih os xilzenx emj UVHEE ofd nkorkekf lgoklh vu kfo xowec zofa puyr bamy gydua wzuzfhud eg jvuc, fix naz jak zuos zanukt ed a toxqf rnoy fae bap’m kone udjihw qi yain axueh RII bierr.
Mae’xi lida, roca, li ejl prav’z wulg ej mi lult ztuc ragvo tu uyozuk. Lo rhen em jea poydorxb zeavg resf hro fexquxewv fihtoqt:
git push origin master
Die’hu qepe i bcefetvuuc igoehk an vrih dpodgub, wi klaje’p jo jridbumlo gev yei. Koo’su ceyamol luqe kupa tfen uvb oxavere vazicagah juird gufubv ceu as jha yeepvi ux u jev quijm’ tamxc uv borgbo lixsigg, beqharm, hzuvnyegq uzh dilweqj.
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:
“Veb lu O hhaije i Hib hukiqupowj djuf ncyizxl?”
“Xis ri E lxoava o xuqaho ridaconopw qkaq i tenaq are?”
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum
here.
Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:
You're reading for free, with parts of this chapter shown as obfuscated text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.