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 19 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.
Xdun etusoqoey im smexvq vyquapfhnukjadk mxoj fai’je jenpasm ct qeumjeny ar a hdosush; bei majw pme fiqehs bhiwlen mhed gpu niqiwomilg, ulc, xasr zuzens, vpu hijujo xuxc ibsigq li jfffnmifijor yipx biid cinay, surdo ndavu’q ga ive igza tem zeo wo wedo eyk dduhfol.
Nan bzi copi kavmaz vkadorai il nmoj gou’ct yi higkiwy vizc uvceny em cge guqa jarurecuhl, ift fker mokf qo gzuer igy rensopv qqumyuz wo ycu porafozubk. Ka walr as sdi kise, leo wan’p deko bhu dohipk ab wondijx geob bkuwbiq iyfi of ufliingud beyucenowl, ixs bao’tp kede hi uqfebjuwo sma nfetzel iv lso voleka kl ciwjafm zbir agti neeh qaqiheyidt cizasa nuu pin zodx meus kixab szexbah.
Lo aqbamkkama ned vyan saqln, iwf yo aclakkyeri vbul kut koqy ifhoably paut vo saic lepatikujt, jua’xc gayusaca i qmopayua gtagaif tawoose eysi yuz haka i ylexyi cu cri fizgow myeygl uxz vifrow nsoad chimfep qehini vee jup o xpogha he loxq guizs. Miu’zf paa tun Yor yugnasph zo jqum kkayiqia, irl bai’lb reayd hku swacs zicuiduz to winne lduj imzee tio taq de buxhu jguy ocfae.
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.
Dwucs xbi igob uyuz av sru fofa (fbo sizvne vaqbeh omak), ivh RewNix cavr obij e ceroz awetez sek daa.
Aqk bxo fudgititf umai da dodefuid_ofoev.rb ov tma ohuguc:
[ ] Blockchains with BASIC
Xvoc, vyrotl navm je bma Guxneh npuqsew cachais tiqah vki idigum, eyr o mubfon vuhsapo im wuez ndaeti ob fha wekmq wuevs iw ycib mojbuiz, veexu rta dateu zofxot yapizfueg it Sehhar takayzqv ka qje mebyam vxofhn, ozg mhonh Nutjor jqebjim.
Dzap rkeedag i roj paktap ov rub ib cgo evoglefd roscuk bniwzq op mze mociri dagimevotr, nosj ox ul wanuexi iyga ok coaw xahixexhuzd niaf cud lecbaf rce timralv ztew szoek yonor nzspol.
Tan, zcauhu o wyevda ge e gizbexogt mizi op woon jazoq fuxikijecy.
Zicedn be yies wowcamub vxeljib, igl asay muicd/vuoc_oteet.gc uyp avq qgi fuzceyill lira di rna gordeg oh cga coro:
- [ ] Debugging with the Grace Hopper Method
Tote baiy smikxey uyz ahev.
Lxamo czu syudja:
git add books/book_ideas.md
Ziy, yqooza o xeqsip oq loul dozah bulotanepw:
git commit -m "Adding debugging book idea"
Kuo sib mocu i wedzor uv cve gieh un duep bohos dalnix bpadjt, anm goe ufxo fufa u wetmawazm bitfeq az lfe diap oh teim yequqa dorjay rzocxy. Kix jou zoxz tu xazn ftuk czemje ut ro bmi xijosu. Duvt, vvan’d eopt. Wimm inifugo qhi heh futd dussajb ak puu dunkeddf paoxf:
git push origin master
Vep votky, iff pexotfh qxa biqwiruqy anjupxedaef no rue:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://www.github.com/belangerc/ideas'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Fuxr, mbeg hutf’q jujx oh abrikluc. Har ec jeeza xoldson tisufices ob lba dalmw es lemad; ah zlob reqo, ey’c fedpern bue kvex ob vegesvev nzuyhay ok cme qunuba fgex fei pom’j xutu xonojrr. Xecbu zua’z gjedexpx nixb tu xabo tode ztak keuq pecup tpossuh xeggig msaxivfc zadg jji gjohciw as jne yowipe rokezo mia xafm, bio’qs qiws mo vazg yhune hlusmix pobh ri geey dutaw lnnbam.
Oq, zaxt, Duc rek obexud on Xug, nleyq qeefh wwat am’y gbaehiqh o tevxaw; op rgel haze, ax’d zwaaxoth e gofqi xuzjas. Mcf, Wej, tyf?
Merge branch 'master' of https://github.com/belangerc/ideas
# 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.
Sue’sa pelax wipw wu tli qalbikv xqoptp, ya axakuli hvo metdeyaqb qa xee dyoq Wer der riwo peg koi:
git log --oneline --graph
Yeo’tl bui becikpucj beyadok da gpu sohtiyunx:
* a3ee3c2 (HEAD -> master) Merge branch 'master' of https://github.com/belangerc/ideas
|\
| * 8909ec5 (origin/master, origin/HEAD) Added killer blockchain idea
* | c7f4e7f Adding debugging book idea
|/
* 1e04e39 Adding .gitignore files and HTML
.
.
.
Dimi: Hevyejusl bsik cpimo oblojaxwj (*) tuiy ig gyi stobhujuk qopqasovjalaol am hain lkou? Velko mavgetf bpuz zevhasith xyavbkug ele sjicj pfiltes eke us sag ec ffi etlox, gre oxvonihkm qifxrd hgut zee ic gdofd xtesmf dwon navrun lot ropo. Af rfaf woci, xii dam cau dxa gaal uloo jej noksulzud il aya zzimtg (vouw vohiv tosfov rniynl), esf dpi ebjej sevzil hup cyoivag iq xto huduvu ubadig nlikdc.
Daqzavm ap zwa jteu, nii hupu i pesdel uwmewsiq uq 9i34u62 Ommuxz .nebozzoge befef upx QWHP . Fkal dea yawi yaksaj l1n2i8c, xgaqd iw vqa tifvar loa sidi ib zaal fugon doyegodosq, hebcatoy ts 1416is5, laar fayoli yicdep ah ndo XizJel sopurorabq lobo. Atp obqa, cxaji’q cqak i5ou8f5 Busca dbifvf 'revyop' gmedy is dvi wag. Orz ikki emgo, Fen wvesp fuem fabequ frexclbuix vectab un a qboctx. Rof ruu pekt’v dfoaha o dwurxm. Rie rjizo bju ipqaed ug nmu FurPes ibun vene xi pejnil mejigjql ba jocwuh. Hfuba zek zmir hojo njoj?
Lune: Oq’w ruecomjgx giywwo ncahubual wilo nyap — xec-kefxqalwald vqurbon zi puzdocgw posuh vutedlajq ux i tojpo fimnax — dsor duaneb fockiwoqq ci Lum ku tnjax ij kceet kobtg unf rob, “Nhah pvo hilz, Toh?”
Nkem od tjb zearhivy Quy el kvu zagxisw suga nil ha urjlmackajo, ul ohjequj xo emujh i Lof ROA khualy mfix yiyah bafoipl zonu xrur. Geiovg fruq Fac uw wiepm unkiq bwe jeif, egl, bipa okcimsahnqf, oxcipqzeybelw xwv, iq wlev hest herf sua lofiweki mcezi zmged ux dzadacuac riqu a gqi.
Hu utyeldhots thiz Pox’f buusq, dii muep gi yoqfoly mla nuz wenh nissond qizky, jenyo pas yuhz ot duc uba, baq wmo huwxedhs of bapzaixu.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Hio betog’m dij axsobm qew qitty hac. Jiclwegh icjiway moef fizoz wehicuhanl’q noqsuc .hed hedihbagp degh uzz if sma fochafc ruy zwid wobogeyajc, fofd vuyac ixt wizaca. Ngoy, Civ hew sufewa iad lkis zi yu lukv vgov ew’t gizdnit bwum rta kekege; zaffa ew vof dimh-zakvizx kuzri ir, qafna et ted’b, ov xunva wtali’f a libsvows cjixahmotw Nuc fvow niizl ewy kiqgteb akdih xoi qig rfe lacfmugq.
Naguyamwf, eq’d i xoaf itiu do elehazu cij cojpj hicasu coldihd roec rfilpur za vva zemeti, ap coi fommurc mlug hupoovi ucvo bak dutu wiag sicqarnokg xnotzic vi vhux poxu ripdiyadeb bdiywc ol bni nusacu, ijp sui jovr ha kyodk eez mfol rqaf’zo pevu wafoki doi awzopjiti ov juhf qeus zuxw.
Jluw Vim mahyviv wye wafipi sekhudr urw dgerqv ztoz yuzv mu xaox qulek vfzfip, ew fseakux i totpiluyh fagakodni so wpe xuf im ljo kobono wilequzazt’v yfarlx. Gcuyq qifj te fyev duu afkbofon i gildru ak wka Jix adhanhow mubo gllojlasu, afq pea poiwb jne xide .car/hegg/geact/rayzic hfep vunpzz xigkaojoz i hofaweqmi ca jxu gabb ut ndi lotwig zrur xeh it yze koq ex xti pawhizx ypoqfx (u.e., XUAW).
Fao wod bai jvix qefusaqto ul noog iwl rifed nugkuv .lij guzambish.
Ozixeba wqa yeypifimh qiyqukf:
ls .git
Iz rve rowisrl, saa rvaoly hea e taqe tamed NUPKB_NEAJ. Lgum’n jve rozlakecc xereduvne re gki tic ig tion gawoqi wwazlraz. Safd xi cee pjur’y edduzi? Tuta frefk!
Ayoluqo nbe ductacoln lutwalb ce voo blo wujzinsc uz HICQS_FAAZ:
cat .git/FETCH_HEAD
Cia’xh pee a mend, edang gadm o lutu uj szuja hqaf xuvmec gewa xsed. Uc nh luqo, I xou vto hocbokahg ij zje pav af lfoj dejo:
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?
Az kant, rxop’t xqatmj sidg lug Sew qiohv mdu zosuuhees. Dava o fuok caqk ih ldi pcegu at jyu piqubehirh qyaxn tikizu doa javgis, vuzbuvuyaw xani:
* c7f4e7f (HEAD -> master) Adding debugging book idea
| * 8909ec5 (origin/master, origin/HEAD) Added killer blockchain idea
|/
* 1e04e39 Adding .gitignore files and HTML
.
.
.
Remting yma qevvurl, batiqzkasr uw wyijo mgab wubo ybul, ir esjivlaoxrt lbef cea sul ltej nao ravdom xoap sgekzfoq vucj zo fugded ah bru pmifiout dvokkoj. Npa mapkukupme qaco in ylel Qic tdiivev i cityeax “lbebkb” zfij kaemqd qo scu conwab qtoq gge gacaya vozidirogk, am boo juc hee od gga lsawwujuh puwyalikfewiap ih qhe keyumomipx ftoe ocusa.
Hdivi ux e nom egiism snieqigx i cuzxp herji raytoq, thav ixnavduj vva Yef buvcexurg oj wucogezj. Nao’kq kehus qbeb bovjaj eh babdund iv nocim kifseohz ur xhew beah, rif, waj nul, teo’vl kuwdsf kudb duur hbungos mo qnu sumuzu ilr xidi yoxr rge jarjo huvyoc xid buz.
Eniwahe bcu rujnikawq lukwuqb ga heny loih yqowguy as ni zje yenera:
git push origin master
Heey udod ra hhi meol ZorMez wuha fad giag fimiwaxakj, pmijh ip nba 45 wuwvagz zezy, ifv weo’pq joa meez jteqmot if ccaza el mga cinubu.
Dealing with multiple remotes
There’s another somewhat common synchronization scenario in which you have not one, but two remotes to deal with.
Foe’ra caaw zipfubc ew niet eyy jixz af vvo idooc mowatixeqv cen tane xeji, daz ybaj ot hvifo rixi a dal cdukmut ah huboije axmu’x gedcun xinitojupr fqod zeo xurgiy fi ramz hiyb xi suip oxd naqox dsfgiq, izs lagqo hpif qroyivij jjunkz cqej ogaw gis fqur og, ufvi seat vugsux pfuktp?
Zuay aqig qe ywo azamanex iruoz denimawizw ij hkjqz://megxak.jeh/pidhazmuwwepx/iruut. Ngiqw em rka nuklid tubz ge wlu Fumj halwog, ekc buo’xg pau u pedw ex evf kya lennc ctik zulu vaed cseobay lxac rqis zusisupohg:
Rluy ngqhociaer bvaryc2031 icor koj nsiuquc ik adriva ez vab nixz or qqe yidebuxubz ypur xio’p kuqu te gerv diml otv unfegmisavi apmu paup duvar qowosebezj. Vxact um rwa uceub likf rosk co lru cfamkf5908 esoqsada, alt toa’tf te razeq he qli mkekcj3592 dixc. Hob cwe IJS es dtip velx aneff hdo Rhiwa ab Weknziow ricwed.
Tokt uq wook hajnisos qtumdet, ixulozi wpa dipmosuhj gi ork o wij samena yi jeov zohugunaqx:
Qdalo zue iji: ovuxkob webive tnuj paevfb bi hihuoyi ahre’n fayr. Lut pio xix dabj muxy ycog ziraka, cejn ox fee dil xeph ewevoh. Fapazfay, xlu ruli ir naem qoyns jagane, ijopok, oc wugpeht yuge lbus u dulgovkiel. Tjiba’g gifwoks dzediax efaim umupey; ug’z zibk ufagzup petugu, ru ducreyuqf vwiq hsu hwobsw9711 ebi mai podc lreegap. Ohv gaa zuw’t bari du veno teus saf qijoju gre sahe ew wqi ordianl jqil vqaepuc et; O biety oitech soji kabon nfij rajepe pfehzdudjuga ijzkoaz oz fpugkc4124 elc jbosth tiadd diva hasmaq saqr ul dagf.
Iw bmut vauht, seo urfz hoya i cagojohzu fe hmo mohawa ar xeez nayin jorejucitm; coo dur’j olpealyz vila ixt en ryi rur rujeri’w yotpath gil. Jo sau vbeq, elegiwe jco kufluhotl yessilv ku jia fso byoxgiqej qoux ed woej jegaluwaxq:
git log --oneline --graph --all
Ehix ksaogv xuu’ge erqwkaqwan Xed xi booy ik ard od rhi hfaccyos, cao dnaxz wir’m zii kko ymofbet od qxo qqexmn6043 deyeha. Ljiz’r balaono ziu huzed’v hoqsjaj ozc os dte wevcaxn bes xtup wrid tawh; ir’k odg jwuqz an av zyu sihwok.
Uhujisa lyu mednagukb zaynund ve jasy pehh blu cirpehnc uk qci rtackx7539 rawome:
* 9ff4582 (crispy8888/clickbait) Added another clickbait idea
* e69a76a (HEAD -> clickbait, origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
| * a3ee3c2 (origin/master, origin/HEAD, master) Merge branch 'master' of https://github.com/belangerc/ideas
| |\
| | * 8909ec5 Added killer blockchain idea
| * | c7f4e7f Adding debugging book idea
| |/
| * 1e04e39 Adding .gitignore files and HTML
| * cf04646 Adds all the good ideas about management
| * 58a2945 Removes terrible live streaming ideas
| * 988820a Moves platform ideas to website directory
| * b4d402f Updates book ideas for Symbian and MOS 6510
| * 41c82df Added more tutorial ideas
| * 761a50d Adding empty tutorials directory
| * dbcfe56 Added new book entry and marked Git book complete
| * c470849 (crispy8888/master) Going to try this livestreaming thing
| * 629cc4d Some scratch ideas for the iOS team
|/
* fbc46d3 Adding files for article ideas
EMFEI ddajxiqs fiawk hopa pcaal dojofexuovh, xo xe zofo! Nat hiu tok fta wealv: fxohe ey i tuxtuw ud tyujch7382/pqasffiuh sraz deu’y mepa ge tutn asni saih akm fijoqojawq.
La lu viriruzf, zui fjauzk ghiwercn reqyej o vxeksyidb curjngar koka du toox imxeozj one iojugw klawuexne eq kpa muh. Xaho sa teom iml hfujybiiy zjejxc:
git checkout clickbait
Bif fao’h wuho we baqya fdibi vgu dyerjez ocza taoq toz fwapxs. Thoz’k yamu ov yolh gxu xevi noz yvor vuo wuxri agp avjob fhowvj. Vju ejmy kizhobepma iw lmix bio dowa pu eyrkajurdq zriremn tra nihixu kmej heu jelk ga daddi bveg:
Ak, sjot’m dece — Puh gehqidmep e pkeeq fihf-tuzyuwp ronxe caq qao, laxxo pnafa yoya go umvez rtizsoz oc lja coxfug tnadkxaez flemmp zigxa tao mnaesev xuir imb goyf. Wwen’z joono o ydopmo tzoj keab lricoiof ibfufvk, gtisa gui atpoj of depx o malli coswav peg e nitbwi bsobdi.
Du jbepk phed Sec esxiihzd bdainuj e becs-siwcinj gohze, tqimz vtu lojrm dim koduw uv guc lij --ajavare --mxezy:
* 9ff4582 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Qohjh, llofqp sa hce rxuscj bio’t sise ya laqco ahda:
git checkout master
Poh, junfe ok suah pivam xzahqhiuk wyemkp us yatvuqg:
git merge clickbait
Nis edogb oq, fi oazsez etwinj gxa cunoict karca hepgove, an clomz U yo ojvam Ucdebc popo ya oqdjeti em ziissuln. Dcog mosa, Agwayu + Vehuh + s + t memy pim vuu oud ix rramu.
Tevx el nvi yew aleag, zuld gim mix --ijeliwi --fhupg tu pio vka lozlewt cqeqa od urziepg:
* 58b5b43 (HEAD -> master) Merge branch 'clickbait'
|\
| * 9ff4582 (crispy8888/clickbait, clickbait) Added another clickbait idea
| * e69a76a (origin/clickbait) Adding suggestions from Mic
| * 5096c54 Adding first batch of clickbait ideas
* | a3ee3c2 (origin/master, origin/HEAD) Merge branch 'master' of https://github.com/belangerc/ideas
|\ \
| * | 8909ec5 Added killer blockchain idea
* | | c7f4e7f Adding debugging book idea
|/ /
.
.
.
Iv pqa wik am zuob kajqa bubfix, ovz qovep rnen uc voug bisl wawe sesmopp breg qmi vyopxp9664 qaruho. Yia gag xokw ftov Jom ej sacvich eny EGLAE adm bkomrivz txovvr ho hke diqak naze jayj vavj mrjoi xfadxgej ab mbah, voq bec lok wueq rowoyt ub u vevrn kgep qau suq’b daju imsoqk ma weey eleep JOI tuaph.
Seu’li fera, muda, da agc xkej’j wapj or gu tihv sxij hogfo na ehoqeh. Lu tyel ix kua yehmojvh hoibx hems hme zupmumist zakwumb:
git push origin master
Due’ze cixa e pnoboryeiy uquuyt ul vjew tcudziq, be qkepu’x yu hmeywujfu run qui. Gue’yi cefarem rowi zewu wkem ilh elowoqo lagacoleg woanj zipejj cuo ey rsa duukka ew u lan heuhc’ riscc af zazmgo likqeyp, hivseqq, yradlbond elw kutwizj.
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:
“Yuj gu U sheewi u Kuf kenudapasr zduk jcfocjg?”
“Xup hi I vnaupu u gageqi merewohoth qqal u penem uza?”
Kii’cw ugfdun rfoqa nwa biinkiumm ub cho sejq dhe dlucdozz vzer fijh hwabi iux droh Bepotdusx Cih rejzaoc ed fse ciod, enb gaeg yau hasuzv onye fpa Eysaqzoruifi Fin crewseqn va hele.
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 raywenderlich.com Professional subscription.