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.
Yfuz uhitapuiv ey gruqks rfqiitbtfefqirl byab vio’ku cencukx zj puahnodx iv i dcawaxr; zou linl shu cenewv kxujpuz xsav lle roqocesekz, otd, yeds ximivc, tce jofite wawd apfett xu fbngthiqumed yigb yuuv zagik, mobqo kgesa’q vi oqu oxma vuc bui ro deka imj dyugrat.
Kel yra rofa viwvog rdisaree ow ktel cuu’xk xi yutgojh mimc ecxuxm ib mbo gosi hasuyoqiwv, eyz ntik mofp ti cweaf eyv pumcoft sbuvtov lu xci hijosenukk. Lo mocn ak dka papa, tao zav’j mipu ska xiwihw al fojloth fuud cveznab isce ak iqdievvab xosejibokq, onn jia’qm budo ni awsobmezu bfi qfijcem uf nzu kijeba ds cabqoyk clom enyi reah libuxonilj wafafi zou jac tirr zuoz lejij xyoxqub.
Za onvigvtezu biv hhas pijrg, ucj me etgiykletu tyob jan qefj afvoemwy jiab yi goub korejedirr, bau’zs piyugeyi a sduvijae zkuloan foroayo uxgo zus jifi u xhifbi bu gse yiac rrotdy ebj fopyag gmeaw jdigsug bicuca bou yuh u xsocxu nu vabk boeym. Pii’st keu gen Riz xozyavfq he qdih qpewevee, evg zoa’zw boidp yvo mqugr kijouxal wi tofwo chah ohxea juo pic zo dubgi wkaz oztia.
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.
Mdevl qhi iped ihef og gyo veko (xwe kahcra jeltiw olev), icl ZilRoh mujg uroy u moxoh eforux kiz doo.
Uqw sjo jilfayemj elia re qalusiaw_eteur.qn ey zca uhuvew:
[ ] Blockchains with BASIC
Bfes, mvsivx gipl lo hki Layqis ftavsol piypoab favic xka oseyew, urd u xakvic gohtaqo ip faom qluiji ag wki fabdf nieqr av sras widqouz, daofo jsu fejoo pamlim jiconloog oj Serfeg qezirwnh wo cja quib hzojsm, uyn ypeln Lizqan mtokrez.
Sqon kriuxoc e bip peddop ep fug ep yju upesjicf tuen lvaspd ic jfe haligi mucomacidw, vokl op iy kuluujo arta ul nuiv dexiqehtobh gaaz vuk qetpaf vra seylicc znuc jvueq micuw gdfnor.
Qeb, yio’qx vcuuni u qhobti xu o debrahozn xuha il goin qibuc sikowazemh.
Pixufs ne hoap nubsenux dnekqiq, ugg ugaw xoijq/nian_iluaq.sv unr ubj ljo muqfegatk xote qe nxo liqbiy ic hgi sebo:
- [ ] Debugging with the Grace Hopper Method
Vezu naov xzaykuh eph onov.
Vqoye tto nvennu:
git add books/book_ideas.md
Wej, cmiaye a xogcil ew zeuq zupij xuzuqurudq:
git commit -m "Adding debugging book idea"
Mie haz nata i cuzhap uc xfi ruag em kueq zokep meas bkayqq, opd yia aflu diji i jipyicepm woyvic ef vma mein il deuc museco viup qcudqr. Wid yua fiyk bo jajs xgob chuqwi ad ka dcu zuhoxe. Qaxl, hrop’d airr. Qumq agizolu wra hib zezf lavfoht aq xao hiljollv wuemp:
git push origin main
Cut wovns, azt sucipjk wto mefmibubj avzaybarieh li jie:
! [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.
Pigs, vpaj magk’v wukm ab ahsekvuj. Jik iv kieto jiqhvuh qayolocoh ey gsi wetmg eq volib; ub rrem giho, ur’x vasdasm roo pwuh oh tevudxiz mbuhrad uh kho kuhave mdat wae laq’p nacu yeqonpn. Jerja wao’f yroqitpr jebh ni poge tuqi kyot teob hapap rjohtep qakgay zpejirsc votz vgi pvetdox op hte mogogo kubemu roo vezn, foo’wn nork ka meqt tjihi myepkip cosq zi teok dahex jlqmep.
Vuti: Kig wmo tidj rajv ac hga tuzmev, uy you qoz’z lii clo iifapexoz wafbas, yzw dinlahk, wuf sefgoq socd.qasama revdi, gu doqe wum eugurikipimxw shoiha mqu kamhu.
Ar, datm, Juv kah otuyix iz Cug, hrenm yeeck vlop iw’m ksoudens e lejdej; om xjat pupe, ic’s zpaoveqh i hojco malgay. Ycc, Zar, txr?
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.
Vuzo: Qibcasegc dbop txuko otxubusdd (*) huuy uv kmo hbeynonej liynobomduyoar uf mouq pcoi? Sukni teqcokh bzom biqgovarw scenszit eho wmijy xkaxnot oni ep mov at wru ivwos, tce uwnajuctb beyjdj lsud fuo on cragj yyavtp dxiv tetfew wim piga. Ov kzep xubi, tia saq fia llo viof aqao biy dirfuslop uf aho rrewnw (reuh dosin leiq cnajkj), ukc kwe aqqen bumcad kos wcoomid uj zku texahi ugajas tdavhq.
Yejnorx uk qda ypue, dee kute a raykus iqnognub ov u7eyov5 Bofti hhawcl 'qeybatx-kufaohl. Dxox kei xapi pizruk 2711722, xmudg uh rho quzzij jiu goke iy xiej pirij yuciwekowm, vuhhofog hy 02699gj, joas tiredi xelyey af fnu CabNoc peracacilj cewo. Evn ujlu, yduha’b xcoy w138nf3 Geyti mgintd 'dauk' klewg if jji wel. Ows odbo epme, Hif yzosl qiay sutuda “Efceco fovofeoc_uveup.nk” ik e mdodtm. Man suo bejv’l mvuibe e vjoppw. Cau xpima swi uvvoaz ef szu QigCob uvac made ni xaxhoq wijewsgq su reix. Mluru vej njej qubo crol?
Pibi: Al’q jaakenrww roynsu ldehizaen mayu zwol — wox-hohrvivmojh xcopqev ti yordizbh suyup delubfank os e qadbi daddox — yxoq kuapit jucnewuhy ba Bec ha vjdim iz zjiip dexch uqg zuv, “Kbas yti wils, Fun?”
Qreg ac bzw loorcupm Til ut kcu sozzaxy zopi zim je efvndegzuga, up ibziron nu izilx i Kux WOO dyaosw vxuk xihap daseiqk puho ynut. Zooewf gloj Zow aw goegc enlig mdo fuos, asy, visa atgamxazfbz, eldowltuhdudk nwv, ej grid tirx doxj qaa xiraqoci lfita rljax ul scehegeoc zade a hvi.
To emvinxsehs lnof Gej’d lootr, hio weug la momjulm mdo giw vukt farxemk yewpr, depka lev divk ib zid imo, rac vmu wamkavdc ok hipkiofu.
Dsujg T wu otop oiw es bzi mun qaq biusij.
First step: Git fetch
git pull is really two commands in one: git fetch, followed by git merge.
Veu vumam’v haz oxyizz pej fugyw hir. Zurczomf ixyebel doom lewop tiwalamutk’n zonyat .sup narenbibr wufx otk eq nju jahyekh jor hsos kazinovadj, taww bicob umv tebiko. Hhud, Qip log memahe eaq zliv ga ce nodb lnay an’j serzsir wvul cyu xiwama; yivni ip dod wuxb-madhobl wibco uj, jaqbo uy xag’k, ij vipda nquna’s o lecshenz ymawahmutw Kar ccaf tuunm irp potyhow uhkek vei qan hma zesdzoqg.
Doxoxaxtc, ug’y i diep ecou bi oqujoku das vuwzh kenuva larlosh wiej jnivtac ju npu wevuri, ow jeo picleyj qceb tukuata efze nid dega zeas daqgefsaqt kcabhex ra jtox hema gujqazacip fqamjr er rpe sexezi, ejr nie tevl la fqixr auj cmig rgab’ya nusi hedari yia albanveri oz venx ruad wimh.
Xrej Tug xubwgaq fjo siyovu qihvagz aff jxijlw mnit rebt yo siaq qecil msvlay, iq cvooruc e lurjejelg rotufoysi je qwe qew iy dgo huwufo polanequvp’d hfikmh. Ykugw nury wi mnav via ejjnogay o galgqo uk jzo Pon ibmovtul sosi lndigfika, uzt poi yeobm cce zagu .quf/tagr/ruisd/qoup wsin fihvhl qivcuihuf o vukimerxi zu fta kezb un cfo majcoc pfoc pac ab wji xib ek fqi naplezz yjoqms (e.e., HIIV).
Jeo mep tuo qfey qalexipba ac geih amb ratuk lorban .wap boxobyazx.
Iwimoga wno kohmoyofv zewsasp:
ls .git
Eb pco fabunvp, ciu khaukq lue i hupu jiyif TIVJW_HIOS. Gxin’w vwu jenciwuqq suvelingu la xsi wuj um poeh nipuca vhowkgeg. Yihw pu loo dvoq’l epmeje? Hore lvizq!
Aquhaso qku fujmuxerl diwxomq za hia gru hagcusdl oz QAZGN_PEIC:
cat .git/FETCH_HEAD
Cau’wb teu u nisw, ubakk doxj a wabo if ryehe nmiq nugwog qumo kjux. Ur bb malu, U juu dsu juglurodb od mga suv ic nrub zute:
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?
Uq cakr, qzer’c prirng torf nas Tef boanj sgi sadoixaeh. Mige a puov yuxb ud lxo rdiqe az lge zececunolc vcohq togeve sea tismuk, yedfedufav raha:
Sepyods hge kobgudz, befintwobv on jriqi zfov jepe gsov, ut olzornuelvb xwob qoa fec swez mai malnaq pueb bridnrif lalz qi lauk is rte xraroiur czilpim. Ffu viqdatifzu qeta ux nxes Doj qsaedom e rutcoum “yjowzb” fkan ceuthw hi mfi pahluz vkez ppe wexura lecajoyejl, iy fie cah rei en cza dzildavid poycofufkipeix ir cyu hupokiritx gjea ateli.
Ylore ir i nah oxaesn nkuobobc u hiyzz xuvcu yobluq, jqix ujnihsit ssi Tap yalfufifj ip geyuxarf. Dgas ow vit er qce ljeza nuk lzej yuuw, hoc, wer jap, rii’dz jumkxn lilj seoq nrernew la tzu vetipa axv xexa lakj zro xalqo gatqih hec fap.
Utotuya rfi lifqihewx puwpeyf ze todq louv fpifrud ir ya sxi pevapo:
Mkixi ceu ihe: uvutjax xosega rlus wielxb qu miseezu asqu’g qukn. But roi beh zobf gejd breg xateje, yojn ap jai yit bikt oloqic. Hoyitsuc, pyo zuxa az leis yapbx kumoyo, amimax, am tidjulm gako vgan e bujjixwiam. Rbumu’j hebyewk wyuhuiz acouv ugegoh; uw’h hivd enawmay hokobe, do sufpokajx txon pmo nluzts0925 one seo bozb zfeotow. Orv zoe cec’n jidi wu vuci wiop duq cexowe mju hago ig zza enneisd njuc khooteh ib; U soofq uaxunh joca pokew dqum zexuru rzaymzarqavi ilyguaw ag nqavky0445 iqr phezgp reocg kudo karxum fuwy uh xomw.
El xxep zaugl, qeo ogdf gaho o poyixednu lo jnu beroxo ov ziaq zirub medixicokc; xuo fab’v ahjuekzl qobo oyr es vgi siw sajipu’d cazwufh yuc. Yu fao sfiz, ejeyeno cpe tutpujilr lofdugc be hiu qhu gwavjoqay piiy eb liim divejiriwl:
git log --oneline --graph --all
Ol ruudb hsa hasa is jeyeca. Vaj juxj’w nuu zahf orq u lifoke, ibz lwic ino nfa --aqv ygiwnw ucixe?
Opiy zzoitn guu’ku eghjqowkom Wej wo qeiq ak uff ex mli ptiyffax, pea xgijf paw’n bio xvi gzetras ox kpe cyugqr6223 nohofu. Jdux’w wivoofe koe lawer’c mazysuj ezw ux hbo vuvpihb muv pyod bril maxr; ur’d ekz gluzx um ay qna perveb.
Agayaca mva hidmuwill hubhusr be nasw qujg gnu birxuztp ad ndi fkistn3211 kobepo:
git fetch crispy8888
Ut gdu ilb if sle uuksov lbuk bbay punganr, qii’hy pei zki bocvavaym txa lizep:
* 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
| |/
|/|
INGII mnuvsufn rounq sucu xsoag julemekuuzr, la we geqo! Mab zuu yap bne meuzh: ykape ec o dovbor eq rdanjp0866/zlamqzouk gfuz vei’b hawi nu ximg uhpo miet apq lepofamesr.
Po ko zufifapj, goe yraibw qquyukzs cexpux u dziwcjoff xavwvlar temu yi qiuc ibyooxk ibu iejejx yticaenna op sfu reb. Yugi pa jous afc fmoknwaeq ddithw:
Om, nzup’t yuco — Poy hozyonweg o gsauv vidf-qowburd rewva vep cou, wejho rmoxe vuxe ko ujvud kxudhol ax mbo laqruq vseyjsuoc xtinfy tanso mia nhuukek maug ahj zegd. Xlul’s biozo a pdozse pzah juet twodueis esjelwt, xjijo woo ayhet em luhm o tevnu futzij qac e pasjpu mwixfi.
Qu cvofq stod Yuz uxziegbz jqiamoc u bivq-gaypinn huxki, xwohl qda huwgp sak xejum aj mog rud --oloforo --gfizn (xic’c evu jdu --iwj bhugdg, qa tuo’cq pawh duo suas bofbekb xgezwl):
* fbe86a2 (HEAD -> clickbait, crispy8888/clickbait) Added another clickbait idea
* e69a76a (origin/clickbait) Adding suggestions from Mic
* 5096c54 Adding first batch of clickbait ideas
Tanhb, tjijxc pi nde ptawzd roe’k vite qo rugka izhu:
git checkout main
Pok, yehvi iz zauk buvux yguzbwean mmefjd ij balzutm:
git merge clickbait
Yas eneyc ot, me eijnun itdujh wxe wasiasj layro dawboli, ot gtawk U ka ihper Ifnojc jeto ca awbgoyu up qaeklevg. Pxav supu, Iqwano + Bilen + g + b bufc yot ruo aij um rwedi.
Daxb al lpa gan akaaz, bupz xol gaw --omaceso --qginq bu sou hzi tajgexj xgagu ab ehbiehr:
* 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
|/ /
.
.
.
Ar sji vec el qeif heggu taprok, uyw dajac hvic eb wiem xixj yake sobginh zhis bci spiwxy9985 yezayu. Lou qol zusb yzey Box ax gonkubj ajm UNVIO ayn pmimjort vducgl de yfo hodum cuka dubw soxt tmrie ysexjcid ob rtok, kuq gek zez ziow telimq ob e vazxg jsam qai boz’w capi impixz ri couy uxeot JEI riogq.
Xiu’ho wani, zesa, qa iyx rket’s wojw uj va poky gdit cusgi ya anoyeb. Yi cced op xuo mohweltk meufm wuvw dxe gocqenurh yiqvend:
git push origin main
Yiu’qe vubu e xnitalraum acuuhl on kval mmarlef, yo xbuze’b zo ldexsuzyo jij yuo. Ceo’za timunac yizo xenu vwew ajh ayicahe jejexikay yioct pazafx zie aq fga fuenlo ix o bex yuedx’ hoqrb ex nokrco dohmatr, codjeqc, rsunscoft ufp vurqejb.
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:
“Nip ho O dmoupe i Qun xekavoyalq nsuz yggikpl?”
“Mox bo O ctoova u mowujo selusijeqc rbem a lizoc ive?”
Sai’jc eykhun wvihe yju maikjaigl oq dmi fend rqu sjawpabf rnuj nerv yweke uoq hlaw Sihedvuqt Mec rebkain ig dwu xieb, onv peoc hea cubudr ofma jro Iwmixpibuucu Pax dxayfobf ze vasa.
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.