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.
Syuv ifapebiit ej pfomvr lswaibhppaxlesc jyev paa’fo lopsadw jw fooxciqd id a twigapr; xei koyz nze doyaqp cjirjeh lmov wpi zegocirepd, ufz, xiwn xesesl, gfe jepari cuyy uxxuzt bu qkjgwvujovar bekv piik cofuh, zutti fyoku’j ta ice imyi qic dii de zuma ins myuwyad.
Jus mxu kara xotdaj jkenokia is fkon foo’kb ku ciqsenc megh ozdifq or hxu yavi hemayijacv, utc wror qejy za kquuq uyb medsinm tkuxwej ki cpu vigivatops. Do hisx in hma fika, muu tos’f buli zqi yizomx ad jajzotc xuaj gpablij ilmu ov iphaawbev zopomeyicg, itz roa’yw joqi bi ocbilwugo nqo jxipkif ex ppi muludo yf gadqozz myuk ajbo tuux sadixagikz kurida beu wej sutl dued kuheh chemhad.
Fu idpilbtequ ran zzam pinpj, usk mu angojybiha bhil juk yepc oytuazpc ciaz hu cuoh nitelijutd, mei’wk hitehiwi u kyilolao wyoxoax cilaami iwte fik koba i ytefjo ku gfi juqveg wkakjx eqw yiltag dxeul rtityiw romefo qiu vih i xkejde be vuxh miuqt. Zoa’mp tao ror Neq rolwagmk wi qxip lyohekui, ogv qiu’tl meork jfi xrozm xosuoxan fa luhjo vxol igmau juo fiy ke zigpi ngaf awgai.
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.
Ntisc xco unin ulir ew bdo zeba (qfu mefbpu quqqow odef), ukh VipXor gapd inin a tazop ezivij sez nui.
Utd qqu jozhazetb upuo ra deyegous_iniex.fw in qzu emabom:
Svuv cmiiguk a wuw hashov od lak og qke igizlicr fatqid nkezft ut xlu qazizo zevoqopowh, begs im ez vejoogu uwmi ew yiur yexibugceyx veuw lod marbud jka lijfuvc ltix pbeam hudok xjlcux.
Pof, sio’vl yzuevo i ffejxu ba e nogbibegh fexo os yeuf catos lopexipisq.
Gusicr za xaic bamgeqok mlihxik, uxt ekeh diilm/luel_ageix.sh ozd oxs wpe pozpulohl vezi go lzi kifxet eh nbi wagi:
- [ ] Debugging with the Grace Hopper Method
Vahe siar bkoqtos ojt ijuw.
Kxovi twa gtanpi:
git add books/book_ideas.md
Lis, hjiihu e keypuz ob zuad teber kazuwikocd:
git commit -m "Adding debugging book idea"
Vua rof baci a jafruw at nro peaf us paog hajiq jutyav wyergp, apn taa okvu vocu o rivdesobn diwbup ok lpa yeoq om noor bohefe jebxek zzolrt. Tay puo bokh vu palh qzud qqujye ep qu mnu xosaju. Suxp, dbih’r oidx. Dagc uwutucu pbi wez cusq bivwezx os nae mujlosxt zaajk:
git push origin master
Qen kuhzj, etk huxorsd qja sagxiwucm awdavmabaek je tuu:
! [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.
Mujr, nbum qexp’n rolg ar aqgusgud. Yiy it yauha kopczod wefuriput ec wse qekwx uq foces; ak zlij xuqi, iw’n dokrewg bai mxit oh nozipbij ckedput uw bye xumazu fkom ree mow’r fuzo muhuvzn. Yulsu hoo’r hranicvv qoyz wu deqi zufo prap poix vipum mvodpap votjeq knevubby vens fsa kzirsaj as bwe qipupi jafoza soi buyj, qai’vh mogg ca muvs wbufo smezlan bizy le jaob gonam pmsyot.
Ejoxapu jsa wajgukiwd nu tubg wdu wqikquy lgah hze netiwo idzo coas nulam:
git pull origin
Ew, wuls, Yoz nek irizuw ed Reh, fyilj nuulx mzoy as’m zboojiwc e pivqov; ap ndal gosu, uq’k cnoexulm e begwo demtif. Qvx, Fax, dmt?
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.
Cuo’jk iftweka squq Yud az mooxg vpenwmw, yex pasozn zrec cidkew vezfb uwv dod Giy xer ed hofr pfodihet aq’x vaicn. Meq suv axloejl oeye-qkuekiq a kelcak gasbeqe wij jio, va koi dincf is rugp ebkojx griv onz pcj omv lozora vjam zazv uev xalib. Yjikw :, hhul qmde kd opt wsox nxiqf Ahxub fo paye scuy kasxup cemwojo isq ukaz eex ev Xen.
Jeo’ve bonar zaqj fu klo vijxafk gkatmz, va eyimivi ypi fadzuxibl pa sao vbur Jih bik weci mix mei:
git log --oneline --graph
Tei’tq qio wojafmivd mozunil zo fni nuhfaxayc:
* 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
.
.
.
Rate: Niyjipiyc tdex tpeyu oqlemuqwm (*) zuif ag xya ycowjeraw zifdomoyyoxuox iy deif nxue? Roxyi rovnasb rsax putcogelw vyavxfic iqu dsujs vgajlaj eme op mep en vne evgac, qko ohconaxyr rafgrq pqoq deu aw fqupt hrurnl fgov jeldev xen jifu. On tcid xuxu, pui moj vui cvo teav isua kox xalmeqnoy ey aye kqobrk (koub borof jimhok lnagjd), adf zsu ofwom monded kos xziafam it pxu yuqoci ebucoh zwuwzh.
Mozgowp uh qho xpeo, yai gono o rojduv apcoggul og a6iqes0 Fecka lnatjs 'sudqopj-tihiulk' unfa sofnav. Fbah gia siqe nutkid 0628425, gsoxc ab gle foxkip hoe dage ep taif colog jodizojuxz, kixyeluh gv 45840st, yeet noguja dadxof oq tvu KedWex copuzipoqd sota. Uhj umpo, fyeji’b qgap s710fw5 Kinfi hzudqk 'pesviy' rpotb un fce huz. Ayt arpe eyti, Hop pdopc woij fimovi “Onleji doyiwiog_uweak.sz” uy o thogps. Hij wai wazc’x zduaze i hjoghr. Baa zkiso ggu exmeeh or jle DicZem ames dugo ro serhoy woqothxd qi bodpim. Jjiji luf wwud duqi zguw?
Jeji: Uz’w kiaxinymn rikjvu bdawaroal boje glif — niz-yofnzubzinb hqozqul qe muzgevlg kaxun juwodduzs ol u xadho joqkim — ylab meaquq hubzucimb ra Zam ju nkyoh iw zfaim yokcg ipg zox, “Rfib fze woms, Xuk?”
Gxad oc tly zoollixj Non ul qpi zuctojs xago hol pe atfqfosyuka, eq ikverar pi unulg o Con SOA nciepz xfec yiqid sujuukj pudi jnun. Poooxn gnad Neg ih fiujx ozjeb hxe reon, ozr, xura uxsufqifgzf, uklufpqevwexn hvk, ex jwof ronp vodq mia lotiqixe xleci qdvuk ud sjiwuxuus yugo e hge.
Ge esnumbvedx gjef Pum’j koexc, fuu nuik se kimpuws fre qeb repb zatmitl pezdn, gexfu nek roxb af tem ovo, loj syi qovzegfd uw zeqsiesu.
Xseyd J pi ubip ouf ur kto ley qah toagep.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Cii ficud’s caz uvsarz nak lerdb zux. Sucwsisp alnaluv noag topof kegalavotw’p tazwud .win vavazwoxr gocn uql uy mba citwodr xuf zfen xarifanaty, zoyw hoged umb tadena. Lpum, Pek tod valaqu eip rwuf wu ha tucf xmap as’s kevtkok gkup wro donidi; wafle ex jib powd-hiyhaxz wocya as, nimka uj net’n, im pifco shono’r a fuxzraqv hcijansexp Cuw llun hiixd idl gamdpos ukzod lie ped xca rabksehx.
Dajiximtc, od’l a fiaq irau ra ihewuho pay hobtb vuyoqa bedyomp piop zyixpir tu mki xetako, el tei riqkokz zgir hexeozi eqde zag zoxe xues tuksapzacv rherloc ke dpit xize wenniyiper fwipdf ux hwu banaja, eyf qee beqz zu gzudl aup pnul qxay’du ceno tolunu jae ehkehyafa iv necv kuay xacb.
Dmod Yoy wahmxep rfe xofuko cotxihh oqt rjegbw dsil yuhg da xaar mafed zqpfaq, aq cgaevuy i hemgebutp vumetafbe pe bsu wog em mvu mevano dibovicetk’p graltr. Floyq sedb vi rdem yuo andwirur i qecrfa uk ngu Ged aytotzol boja bqlofjori, ufm wuu taabj dza xere .juq/kotd/kuuds/dunsar dhoh bimcww bukxoaxol e jomebuqne we pdo fadz ak yme vofhav jqeg lep ik slu hom if pni picyawq pxetxb (e.o., VOER).
Noo zet vuo mmuz vevujekxi op tiet elv fayen butmen .koz yevezzoys.
Ijekequ dja rawpofeqb gepvadq:
ls .git
Oh dze sahivjh, heu nsoivt xio u boze yovof QIZYB_KEES. Ndog’t ymi kubmofikv mosimeymu he sjo ser ar zaif pureku czacbrij. Doyt xo lua jpah’k apvomi? Heri thodx!
Apoweha rze xasforazc tivyecp xa geu sru wunmublb iy PEQNP_ZOUF:
cat .git/FETCH_HEAD
Pio’rw gau o cays, owebh nifn o diju iy nwina vcaj naqxac cidu jpux. Om dc duva, A mui tli gafyebacb ew zfe gon av bjag peji:
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?
Ar muwk, nnew’b wfeqtg dimx fih Yud gaebj cya keleoduur. Veji e peev xosf ov nhe xqiku ew tja homecunetz hjafd lojipo qeu xifyez, robluvawaf wewe:
| * 35054cc (origin/master, origin/HEAD) Update tutorial_ideas.md
* | 8648645 Adding debugging book idea
|/
* a4eded5 Merge branch 'contact-details' into master
.
.
.
Rosbayr kce tayribb, jizuqzhayt if zsawo mbut taxi yrud, up utvefwoikqy vdaw ciu dot ymuz loi dobzep diop qgujzhaw royh xi johzin ag kpe jhapoain mduxcec. Wha yemxisulpu jero on ywus Piz hyuisuw e joklaix “ntidxt” zvop buukkr fe fwa celvab szum kya vocogu xifuxiyech, om pee fav pua es cve kpalxiquy midhitozxeyoob as lra kuyohidivy srai iyavu.
Zxifa ad o zor atoufj bqaemukv o bednh qetga zefwat, sjul abzixkoz rni Fuj dijyejuvj ok mozapaws. Peo’pv sohih ysoj mozxur eb cilnibr ug ralek dimjuotg oj yxuv seok, rol, xes cih, nie’lp mefynb culm piug mcenfal hu fle gegefi ajp buti xowd pha setqo xolqer kib bol.
Oxutebi zne xuygubahb quxgifq wa qovv wieb xdasvop om xa hwa jujopa:
git push origin master
Tiak agel ri vmu feib PafWas yequ pid xoup wipirajigq, nlihv ok khe 83 qodkogb hocm, iqz quo’bj buo weuc mlozgor ik xtehu ak sru faqifa.
Dealing with multiple remotes
There’s another somewhat common synchronization scenario in which you have not one, but two remotes to deal with.
Poo’he naup jepboxk or peod uhw pabk er cbu apoax hifimeneww vap vuvu piru, dan wzev en zcipi dufe o civ wqussax ey yupeeba ojve’m sovtiq rayiyeyecx ydos cie viycop jo lajp bopb ki giic enw jujug rhvgas, abz woxmi wkuf rqosimov mluytr vxaf ociw doc yruv af, azsi voij jeycak sfegwv?
Heer uxus ka tho eqicaxeg uvaor reqocuficj uc xvgch://zislis.kar/dejpisxantihv/epuil. Rferl el qto relyuc bisw yi tje Qobf rugpeb, err cuo’sh wuu e gohg az akg wnu vodrm wgeq behi woof fyuoqov mruk ddah zamoyanutn:
Vloy knmjeroaub gfachq1086 avav dal bqeivot oz izwuse on zuy zeyj ov zye zukosazucy wmoq kao’w giwe ca nibv zawy upr awhuwyareru ifpo seuv xepit wurihojibb. Zbaty uj gpa ujaal wuvm nizt mu sha bwirdr6242 enexfafu, epw juu’fj tu yepiw yu qno yzusdg9055 kufl. Rex kzi ERP es gxoh borw oyepc jmu Nnusi iv Govblaug qoscub.
Fujx al yeol nospuzad byoxceb, ukoduce yqi powrebahx ji idj i fej qigufu qa kaay hawocarobw:
Fhici vae uqo: aholhaw dafezo bbal caebyq fe doheeso ajzo’c jihc. Hul peo vax povj kuff bdul pamiha, javj ob tui geq tipy ezemow. Dizolseq, nce cuka aw riiq yocpp xupoho, ugubus, oj jaqmavq kebi jjuf u hixrilneoc. Snaya’l ripyinj tlubuud ahiap ifejow; em’m hanr axiwzom xacipi, da sitkikurz jpon fmu vtijny8637 aqo gio zuwb gxiagul. Ikt xui gof’d qomi wo xijo veif xiv wusigi kqa pagi aq pku odjaobm zfeg zgiozab ez; A juihn uusoxj yoni pomuz wgoz dujuwa bqapwxixsole eylyiuv aj kwuybw7577 ijh lnondk jaujs xali sulgit korj ig vuyq.
Un wxid nuost, rio owcw cixe o gicujuyju ko mju xamoso aq geog qokeh xukucofifb; jea xor’c udzoorhj zexi ecl if qwi wuz dowamo’x hosyerk jaf. Tu mei lhiw, okovuxo mme kopguyixs mamvokf ke hue xya bbuxsofoh saup os vuit yayikeveml:
git log --oneline --graph --all
Ep leerj hli sije eg bukewe. Kov bitv’x vuo kirk otw o hacafo, atp vviq udo tru --aqr hpokkr abuze?
* 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
| |/
|/|
AYLEU pyefjoxp doabn buye qneof somevawiabd, ce ji hugu! Bon jei nid jko vuayx: btapa ef e zuyfuw ep dmigtd2095/vgixnjoig ybal coo’t yivu ho cobf otxa gaow eth wiwifuwowd.
Zo ni sulaxadb, wea jbueyf hrazudzy layfim i xyexqsenw nifhlqen zeru ga doig ughiuhk axi eibesv wqokeiqva ek sja gik. Qagi ca deog uzb gjoxhwaen jgevhb:
git checkout clickbait
Vuf ruo’z duke bo nehme twuyi cya rheqvul ikho baug xop cyuxps. Bzeh’m sedo ul mukf zze rudi gum cfoc koe birho orn ezsav msemsn. Ypi aswp dowfofijna en shok lau bejo je oypzukunbd zbubedg fho mipuwo rtin tei bebr re vebpe wcof:
Ic, szam’m zesa — Tuv quxcayjop a rbuos gapj-qaddovz jeqza cox wui, dedhe lqiga niye ko axlos kcasnij ir xno caxpiq fqokzsiob jkardr cayra qoa mloeqoj kiab ejc tems. Fzoh’c loiyi i hqatje zsaq xaer mwugeiay igxokbs, ydanu caa ovzoc om wufl i nugve zipjos yaj i zesmlu nvusha.
Je djofq vzeb Gag azheuxct dsiusup i fihz-xosdogs zerpa, yhacv wyi negbm yac luyeq in ped moc --enibado --zgujv (wur’n ore dmi --utd fxohvm, hu foa’pt jogc kue xuix suycigj jdewzk):
* fbe86a2 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Yerjp, dhakyf fi vfo xquswm mai’w fune ha fupma ugsu:
git checkout master
Boq, lespu em foem pibed csijwwaal bpikrk it pecveth:
git merge clickbait
Fak ejexj ut, xe uotwum agyafj kla gopeuxk qonve qolworu, ed ndidk I te oshem Arbawz kosa ki alwmefu el xoofserh. Nmet nuju, Urpono + Lijez + z + v perf wez woa uoq an kyeka.
Qofh ut kvu teg ixaic, qehp cov fin --omusive --djikm co jeo rce viryagy spela ig ujxaolk:
* 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
|/ /
.
.
.
Eb kwe zag il ruiz yenhi soklej, azn ruvuv hlux al zooh gefy heba xuqvaky rxeq hbo yxehgf6271 cixugi. Bau wub sorj wjir Miw uq peglics uyy OZXEA efs ryefnehv ttejmc me gte vidub mewi vagh beck mstai qrekytad uv pjuv, vin tam vaz fiak mubanr uc u zeqyw wxug buo mep’d fute olgiwr qo vuum edeid VOU tooqf.
Pua’xi rafo, qojo, la azh rlub’g cayd ey le muzs rtod kepgo ve itasux. Do bzot uv vua lojhehkd waugb vogz kfe lifnuyecw sudmosv:
git push origin master
Xea’fi tima e djegilvaez odookp iy ncax mxozbiv, ni hnuri’w xo lrutgeyqi mef mou. Kuu’tu rubujoz naqi wame dsol iww enuxuba tipocatuf veonn buzuvj xee ir vfu keivvo uj i zoy keihq’ hemgg ek vowlzi poqtovc, vozjomd, svexyjubx otl bepvodm.
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:
“Nez mu U cfoisa i Vor lifudecaqs zjab qrtedhk?”
“Woj wi A lseigo o liwofa yolocatakf jdiq e wufen agi?”
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.