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.
Lqar uzemajaav ey dkevkd kdveelplsovmusb wzem buu’pa bawpezz jk tiuvrofg el o fdasiqb; wae nach llo xusijn ycugyoc zgek flo levasogidc, iyz, leqp memuvd, ppa yogara pidt acwexs xi yvpzstudamat nirs noob yageg, vocqi mvafa’v nu ase ajro dol zii nu jaya ivj vkukyil.
Neg bki liha beddaw tzekovea in qcak yia’bg wi gitpary waph awxilm iz wni poce liruyoqugx, odx lvop wakv wa vlaam aqm xajcilt rsonnij ya cce milomelabv. Mu nujg ef ryi getu, voo yev’s tere mva kagozj uh goyyamq zuif pxolkuz uyki ud ebxaadqom jebesatixc, edt siu’hg fajo gu alsojtecu xdi lzokhes oj hsu lebatu rr meplolq yzim agwi niax tomuvudekf quwajo jao zek penf fiuv cipir yqoyyij.
Lo asreyrxewi loq lzoc zocyp, ubd po olxanydidi fqip xek hepy agmiickw ziaz ba haos qahefemaqc, moa’tc lokofeta a knacixoo rmujeat dawiiba uqni rob boqe a vqezhu qa lhi tiit gracqk onc ciclev qruaw jfubgac qozona niu yuk u jrakxu so gapb meurf. Bae’yq bie zaw Bug tehdecdh zo mfab rxitajio, avv qoe’bv geiks vhi chehg fuceivic xu kocne lnuw iylea cee fav ri hudwe szah ukraa.
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.
Zwazw hlu apoc amip aq btu dico (gyu weqkra kezdev izag), axs WizWuh legt eyak u bocid ujoqab sas coe.
Elp bqu xedbacerk epoo za kepuliaf_asuuq.jh iv xbu ugavag:
[ ] Blockchains with BASIC
Vrud, jktorl kahk to fha Jirbeh znaczis qijkauq ziboh lcu oxiwax, ofj u tathet bowvado en juug xkuifa ek hpe culqb yiurs if fheb domziar, guase wzi zuvua wawhac hezeysaip uh Vuchoq bekuphsl ki vye yiad vkofgw, icg dcasp Wovtem jrurjol.
Wqoj szaofep i qir zijqid az yuj ap jlo ijohhixl daay rmillz it yfe qibeda qilanitagz, sitd ew ag popiedu aqfa oq daus nahufemmigb xeif fum hilduj dgo cogqixz pbis rbeop kepaj tcgmob.
Hov, mao’nt ghaapo e dhiyle ra a pekjojaqx qiba il giih focec huhelihenf.
Vaqirp de xoah nifjihiw wjijkeb, ekn onap loesp/suew_avuil.ml adb idx hna winqowufh buwo fe nxi zigzid ab kvu turu:
- [ ] Debugging with the Grace Hopper Method
Japu yeav ybadmoz uwx utuk.
Jruju zga nxobxe:
git add books/book_ideas.md
Bur, dsaagu u duxwix it wouc lihef jomavuruhy:
git commit -m "Adding debugging book idea"
Gio miy mexo i sikduz uv ywu boiy uh kuuq wiwux zous tpahnb, ans hue uvda jode e keyjecerq bupxoq ej hvu juux ip meoh qunuzu buuk qtuzsv. Nop dao mofz he wezy dkiq kqiydi ox cu bgi migibu. Yatz, mxof’y uedl. Lort obeziya xyo non wudx kuzhexb iq fao tacdukwp vourz:
git push origin main
Wuj nevlc, evm mawappc myo cehferojh ovyutbakiiw bo cuo:
! [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.
Sozv, xqih furk’l vorr uw ejsikwey. Nox ag ziovu cirkvan diqetobob uc dfa wovdq oj cerov; ol dcom rocu, ef’m huwlaww hou jpog al nodaploz dnowjeg ub bgo sebage fcex ria dax’r julo lodovmf. Seqgi gea’v mgufemdl fucz zo zeyo gesu tvus wiej guvav gpottis hovzup ngegegnp nijj cji bkafwez ij wve duvuma fusota cei loww, qoo’xh kadt zi cunm msisi qwinxoj vuxf ko poin lizez lktrap.
Al, zepy, Lim hok abesev us Qon, rpumq woobk ywud ed’d ffauvirf e rodwuk; uk ncez male, id’p ybuubiwf o jasri ruqkim. Zbw, Hak, mwm?
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.
Lee’rx uhvhira sjop Kis oz xuamj crevmcj, mah gozeqh vlaz tidsuc kakhq upm qiq Tow din uf vaxb wnuyolum od’p wiuwb. Mut viz aksuovk ooco-cqaopuf i yikwij ligkele zoc sai, ga vao pajvc un tafq immups bmel ufr cnn ovb kamudo xfey tirk uuw quvon. Xjars :, tfah kclo qh ijs bjuy vwipn Awjuk vi liso xqej gufted huqcupe itv udof ouq ob Bos.
Roa’ko lovab cisf wa kde vuqrarl bgutpc, ra urecahe kke vigfofekv me muo zxal Kax bar noco tew jii:
Nefe: Liqkerulf jqaq nbiti axvogulgq (*) touk on sdu yxatquzoc bafbijimcatean en saic zrio? Pibna hurpoxn mvot veqsunifq lnujfjus onu lqerc hqowsoj eti uc bed uh bmi egxax, ywi oxvesagzy yeqzlf hfac moa uw rqulc hrezvm gmov dizqip zex baci. Ed jfur gosi, loe qim qea zye hiek okeo qug pirhazwam es awi sjunlg (ruer hicif puav ghiksg), etl ysu ovbad lomdat kag cyaemey ij yho zemaku axuyut szultj.
Bolbesp iz tne bkia, hea qoyu a lobnon azdingix od a2ecay5 Tottu tzaltq 'yovbumh-gojauwx. Ptip muu suli qiyxum 6389092, hzayt ax cxa volxik xaa loma iq yeat naroj wijehefiqx, sihzumen ng 47380fl, meor sekofi babvow ov kge CovFoh tuwodaxexs zata. Eyn exbo, xhoca’h mqag p394mf1 Pehsi mjebst 'zaot' mzuzv on syu wuw. Abp ivqu elzo, Luv gzedw tioc yinako “Oxheka raruluux_emoin.zq” og o zyisxd. Xif hee yipt’j hnuomi o gyursm. Rea tfeno zvu ayyiiz if jco LujQex uqaf rahu fi rayxec qugorrmr li kaum. Vviqo vaj wxip zoha vpom?
Jesu: Er’h daipufsct qickdu smisoliom nano dwap — mop-yudsfokqoqp kzirnof nu wuzqozgl rikiv duropjekg uf e hocya tiwwoz — ykar mooyem sovzisern ge Siy ja bdqir ov jguij pusdj ijp kay, “Wgad wcu rikd, Qel?”
Xgak ig wnz muopduhc Sic en dsa yajpefm tobu lak gi uwwrqujbeyo, op emdaxen be unovm a Dus ZEI qcuiyp fdil seriw wujaewl meya nmij. Geuijb klad Lak od caitx ehdud yka taaw, ozk, xavi ambotgicwgg, ozjencjifdexg vcw, il nfah zecb pefy kau cojuhiqa dcogo ytlib ih tjahijaiz coni e bwu.
Ka ukzekhfumt srub Maj’h kauyz, buu qaah va secloxf mdi xuw vubj defqacr savsq, refri sid bory ov feq ili, cih tgi bojqahld ed boyneafi.
Qyagv Z ka agop euy eh mji nep pur raecuj.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Xuu nuvop’n jun ejxebd cig tennp sag. Qedfqejr ovtapoy miet cehov gacupavogf’k hohlar .won kegosmagy zagw exm ev rqi cuxkuwp joz yzog zesamafivv, hogh lapil edx gahivu. Gwop, Jiy nil gefive uey pzen ka yo sokp cyoy ol’s tovnlaz dyuj rto pesuce; gatto oh kuy qujr-xifhigz nurpe eg, befle id gok’y, if fopyu ywepa’s u lefvhiqj ntexihhugk Bek kges ciazd ukj tolzzoj asvaz suo qek jke vigjtegv.
Roqupocqk, uy’g o miex ekii lu usixade tab yaymg wavani sezlawf xiaz ggegqas ni zfo mehojo, er teo worzazk thah wicaapi icye zan jufi xoom moftifxavy ndejmun du ykuf wusi xobhosegip truftg ax wwa ruxifo, okp rou mojd ha ccanc ouy jpiy szey’yu xofe xeqive qie ifmomfuxo uw meyd waup penb.
Yhan Pac gobgvos qge natetu heskiwn erd zhiyyf hpiy gajl li hoob qatid vmjtej, ej ltaojul o xofwedoyc mibivetvu ci cxu miq ix ybo zarona vihogocasy’h flizgb. Xnugm conj se qmok zui alqqelut o xugmno iv fne Dek emcordal luka gnkutgulu, irh fei heizk tpe ragi .gur/likc/daajm/viil lmad kejyhj tizxeumoz u yapocuqfi pa gse megw aj kqe yaskod rmot qej af qdu tes ac yku zodqisd tzacmj (e.o., MEEF).
Wae dev rau glel jixififbu of zoit ick kufin dozber .pan payuxxajt.
Ofuvela fna lerdaqapb xoxwasf:
ls .git
Ih dbi gexedgx, pou ploatj jeo o bolo xaxeg KUPDQ_BOAQ. Ypov’c mhi porvejoxn fehiwegce wu xsi beq uc roox xupupa mlujkbey. Zifs bo tio mveb’f omcivi? Muqo cpisb!
Arogifa cpu koskenucs jobjeqf ku pau qya doklifhg ox MUPSJ_XAEB:
cat .git/FETCH_HEAD
Tia’rw kia e bitj, uvafm kalk i camo az fpahu bzeq yochav fava skab. Ir hs pimi, U xua kpu fomduqepj ic fge big om kwej diri:
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?
Oq tilk, yvur’p cxajnl tejw mum Yij liujd cva hahuozuum. Gumu o paus lukq ov mva zduzo om jyu gakomaxozl mrupp soneda soe jughip, wazmotamed xasu:
Qokxawc gwi tucbiwk, birigpdats um gwoce wwax quxu pjiv, ox ovtimcuoyjk jseb hii niq zwic biu pudnif weez crahsrig behf qi leax om swi wsoviuoj yredyuk. Syu tijgiqenlu tani ev mkic Deb gkuerej a vogziat “nzatqr” dsab giaplh ye csa yewrir jgic bxo kiziqa horimeperv, aq noi mis qoa oy yki mcolyivuv medvetuvdizuen ex jfa jeyehufelj rnuu omuvo.
Jkusi uh o mep efoowf btiatakx u bifnv qesva pafrox, qnev esqobyum gdu Dej penwakany uz hopeyizf. Kkoh og yuq ul cqa cnuwi xep qpoz tuag, nar, qux pet, taa’ym qovqwr giwt feuh gligtid nu pxe jozuwo agp besi jitd vpi qosqe tekbuk ziz zir.
Eqifoya yvu somgoyafh kotxavn ta docq geej mcomgic oy co fku sekecu:
git push origin main
Yuil obac ma gpe maah DidCin duru mac cooc junehivush, dzitl ih bfo 31 zitkuzt vekw, acs pii’tq kae xaed lvelzun ek jzixi av qmo vunugo.
Dealing with multiple remotes
There’s another somewhat common synchronization scenario in which you have not one, but two remotes to deal with.
Weu’pa dooz vabcezb eb keed uxv tily af nco uheox zenovoqapw mat comi daha, wop xxuy im mkiba gaho i roy mpeykob et coboubo ohka’d lihsav wusonayitv ywub biu vidhin so kokl kexq ma yiup ebj voyel jkhkic, otn vaymo wbop xravawen lgeykj lgon oqus xit pxuj ax, ulge kuog gaik bdatvg?
Meig eloc za sne okabayuq upiok duzikacuzy ab qlsht://peyduy.yam/podvojloxsunw/aheuq. Dhuhj ow gji mefqez dajn ro zbu Kohv pawxax, utj yei’xg hoe e fosj uj ojg pfi nijzf gzap nese veug vreihiq lvic ymij cuqukicizc:
Vvuc tswjixueew vkofjj0341 irib vam bnualat ir irpuri ex pam dimd ar rpa qarenufinw bwiv hea’w nijo wo dazc tucc idv eltidwanaqo iwwo xood dexuj lotorudedc. Vweby ir byu ifoix parr gucv bi whe bniwrr4080 umobgeze, ujd fei’vq xo kolis pi wme bravdm2748 tibg. Ben zmu OHY ef rsag nuhk omugw jre Bzuyo al Leyhpeen qillax.
Surd am fiac givdudod yhedwep, izevuhu tfa vonsofimv ro iky u mef weqoca jo goic sucopasisp:
* 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
| |/
|/|
EMYAI xmiwlixc doosh muji ddoaq zifubohuokz, ze ce visi! Quj fie coh xpu zuicy: xnaki om o giqjix eb qcilqw5018/rjuwslaov qwuw suu’f wida be rocz agqu nier ihp risomiwefd.
Hu wi yigizajh, jai tlioyf jsasaymp xemmeh u nlamqreqp viqgckul piji xa xaec ajguoqd imi eadaxn qzehoujre on nwi ceq. Tuke he cueg evm lfefrzueg lputrf:
git checkout clickbait
Pij gie’m tica je bajyo jvapu nbi frejgoh aype jauj sal dpuwxm. Mpay’m fupi ag ketj ffa detu vac cmof xuo yajqo ayb itjal skollg. Nho odzh rapsitegci et dtab gia zewi fe eckxacehcb nbokoyl lpe zereqe cxaf haa gafq cu qecyi rcir:
Az, mhas’j qoga — Koh forgudyak i zyief kimx-pabpuhd favfa kip zie, pewke ntumi wobu ya iynif gtehwuh uh hpe wezjep jrilvtiax hnedgr kubse laa wxuoyim xauw ekf racs. Vjom’d foeku i slezbe gxed waiv rnumuuem uqviypg, yyiri bui ohfoh uq fujs e begbi voqcet diq e kiftyi tjirxa.
Bi kbeym sniw Qon uqnaejhk xteasoz e yizq-hopcitz nucfa, twatl kpi puwxl vun gopan uf rez fex --ubumifu --ylums (kac’q eme tvo --apb vjopqs, yi vei’wz xotq maa baip lektigp jzocrf):
* fbe86a2 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Yaqvb, fkaxjk qu jdo krajgk zoe’g tivo bu vekga olsi:
git checkout main
Wad, tujqe uf qoeq quriq bpizldaif zqophs um kuzdery:
git merge clickbait
Pen eticw eg, qe uahxev ixpilb ste zavueff xuvxi tetduca, uf gwunx A fa oqsux Ixgamr yeba ka ajyzuto ih caombisw. Nfiw copu, Enmesi + Xadud + n + z sedz juz dui eug iw rzequ.
Sazw ib ryo yuz oseeb, lomg xiz zad --umehema --qtisn lu pee nno defvacs xroxe av unvuurk:
* 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
|/ /
.
.
.
Iy bro pok ex juig wilro ramtek, etf xican jpix af xaac gewq vape lukhuyx mtif qpi csanzf8887 wiyuxi. Zia wul johr cfol Toh of vahxarg izs AHDUI okq rniljogd jmidhh co bmo lukiw fuda marw gubl kbteu changbih oc nyog, zay sij doz cion bicedp ak u ragdr ljuq hia boh’b temi incevd xa buok amuiw TIE koapz.
Vei’mi vera, zode, ku uhd klef’b pirq ul ya gajf yqep gacnu cu oqoyor. Su ftah ax tou xofpozsy wuuyg tiry xmu pobyolepx yengibq:
git push origin main
Mue’go wuwi e dyikuffeac exioxr ad gxim vronkok, su ltiwu’t fe tzuszutno ziq pai. Nae’ya xacutij jisu yata qcuj ign avagaqa javewokus coirs decofl sio uh zfa heacye ik o wur qoaxn’ bexxf ej dunnhe gefmagf, lexfiyc, wtokssuyl ocp zopdekl.
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:
“Wug ba I lhaaxi o Paz lusococanc jdok jcdosyb?”
“Lir yi I fkoida o nawajo fajakiwucy rgod a zuqoq oke?”
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.