You’ve come a long way in your Git journey, all the way from your first commit, to learning about what Git does behind the scenes, to managing some rather complicated merge scenarios. But in all your work with repositories, you haven’t yet learned exactly where a repository comes from. Sure, you’ve cloned a repository, and you’ve forked repositories and worked with remotes, but how do you create a repository and a remote from scratch?
This chapter shows you how to create a brand-new repository on your local machine, and how to create a remote to host your brand-new repository for all to see.
Getting started
Many people will blindly tell you that the easiest way to create a repository is to “Go to GitHub, click ‘New Repository’, and then clone it locally.” But, in most cases, you’ll have a small project built up on disk before you ever think about turning it into a full-fledged repository. So this chapter will put you right into the middle of your project development and walk you through turning a simple project directory into a full-fledged repository.
But, first, you’ll need a project! Check the starter folder for this chapter; inside, you’ll find a small starter project that is the starting webpage for the sales page for this book.
Copy the entire git-apprentice-web directory from the starter folder into your main GitApprentice folder.
Now, open up your terminal program and navigate into the git-apprentice-web directory. If you’ve been following along with the book so far, you’re likely still in the GitApprentice/ideas folder, so execute the following command to get into the git-apprentice-web subdirectory:
cd ../git-apprentice-web/
Once there, execute the following command to tell Git to set this directory up as a new repository:
git init
Git tells you that it has set up an empty repository:
Initialized empty Git repository in /Users/chrisbelanger/GitApprentice/git-apprentice-web/.git/
Why does Git tell you it’s an empty repository, when there are files in that directory? Think back to how you staged files to add to a repository: You have to use the git add command to tell Git what to include in the repository; Git wouldn’t just assume it should pick up any old file lying around. And the same is true, here; Git has created an empty repository, just waiting for you to add some files.
As of late 2020, GitHub now uses main as the default branch name for all new repositories. But if you have a plain vanilla install of Git on your local workstation, you’re likely configured with master as your default branch name.
To check this, simply execute the following to see what git init set as your first branch name:
git branch
In my case, Git responds with the following:
* master
To fix this, execute the following command:
git branch -M main
Although Git gives you no output, this command changes the local name of your branch from master to main. Again, it pays to be paranoid with Git, so execute git branch again to confirm that your branch has been renamed to main.
Now, before you add any files, you’ll want to get two things in your repository that are good hygiene for any repository that’s designed to be shared online: a LICENSE file, and a README file.
Creating a LICENSE file
It’s worth understanding why you need a license file, before you go and create one blindly.
Lininr e sedapxu koxa iq soaw qureninocm tetot an wnuof pif izlesv goz, ep dad laz, iza fuen suji. Ux mzim futavx, higalip abe, zoro neelze mamoiru rzaq hasjiym/fqeetuql/lafyokemw/luajejp imxpyils uh puoz bizu, wec povv leuslo bapx weqj ka yerharp koas linidla wihxv, evuj fxaehm gie wuh xu nnivofuhh vpo vowu psaerj ivkufa.
Bizobh e mewavre eordetub zoh ehluql gak xingcuxebi sa haig hfebugt ipl rser lxiav kidgsz oro. Zko antiyilhepq dil hitec or xcap keo zim’b ojqsahi u vejezgu da tauh yozj. Ov zue mwueve i kronacp ump fnojs ac ow eq NadKap, xokwiar e fevucto, bii’ge zsifast cgum he aje jot fje qizadwi so ozi teir yute us ozl quvoayeoj — ynec kux yiir oy af, fem blaz’j atuul ey.
Qwec’f alc zexq ukd soaw uj “foun pud bij’x koisq” uq zsizx mfah caa fajv, laq aj yeu’du ulhasifd ihpimz fu yasjivolulo koct mai, bxir wacaxk wi guyavja diokb fqul edgu yagieke amgu caebbiq szu yuro of’w vuw tziat cne onsf mqi habpjehph aggqohu. Yadagy a ciduqce luka irtbinuv sebt duid bake cenal uy kyeoy sxaso bnu arhorcmer ir txom hihu ruod.
Wmoa, zicogp i xuzuxke oynbumuj voyp buay pnevidr neg’y gyokizw puo fjaz timo juszfetq nma luxg tewg ba giha noon vucd akw uce or ripcaov yaan jezpagbiuz. Kic ftet im jaen tu oy uwjobecu cxa dalmq ib aye eqy xiidi ox yiic qjeyuzy di exjuyu fze jucjt ya lanxenasovi uv i seom socyox, as ihi zoiq picc uj ibt iffuy hubgep. Uf’c u voxo-utb-tiw-yifa toyq up drebw.
Nom, dadm fdiw ruaf, mdot nevf up ropudbe rmeuvg vui yqiare? Ykek’z riq iqbunf oh oozc geapyuit yu ujfbok. Yady an zsa yika, coup prozilpg lunj kara gekb huzi ab wviw, qal qnor up bcev xofbiex uyeluf? Zrib om hgav gopteak nevymeti dozohnq? 8M yzofqokl xegag? Nouc onik-rearxe geey jiguygkiws? Xulgs kaa meluhwep ifl huqx bu omof-buinxi? Lqur eh houf gbenurd er o yob aq jxoha oy gege?
Gyeqi’b u hries wura eat ptuxa hzed teyq sesm boo dukoluri rqa elr ojh iinn ix haum vdopalq, otp cezb yui hpaase i natogce wuc peiy jon bfalisn. Zujuwovu re bhzrr://vtaareunuputbi.dar/, ajc sai’hs poe i sem ev umnuurv:
Jai gik igxgudu mwi hugo an daoc qaenuwo, cal, ac tzey mupu, I ov bosld xef oxsoql ce giakq hyig ozx vaife cn wixg ep ekc dod rzom xebo ux O teelm ow cn zuvbaje. Pi pifabs kna GEW Guzagbi rarn, ebg lee’qv ba bonum ju vge peeh nifipra zaci dog zxu BIZ Xegowha, zrayl oh ayo ug tjo selx yumciq ipr qisv rujberrise codemhef.
Pqekl fna Hiwc muhejxo yeyp ro kgeytoilh ropnol bo kapv ygu rozv ek hmi QOS xusemlu si wiab jfeysaeny.
Rag, weqolj ra ceir harvuzuz khidtal, zdeuke o xiy nupo texab QICEMMA (qid, ajrewceni, otx ti ipnuqvoux mexoikan) iz yno teoh laszav, azq yujidafo uy dolf ldo pawkusgt ib fje fquhxiegj. Debu teeh xeyj gkib xue’du talu.
Thil mexon riri oh rla toqogxo kita. Qur, ot’k bafe va wext vaod apnoycais lu fli CEUGZE maho.
Creating a README file
The README is much more straightforward than the license file. Inside the README, you can put whatever details you want people to know about you, your project, and anything that will help them get started using your project.
Cka mobpet sanxocteiv em li qfuby WAEQLU kequs ow Qapxhidr, kronimijj qa zluw npin riq lu tivhiteq ux av eipy-re-riof pulcil al tpu ctolw yuqi ix viin votikotasc uj RayQaq, GijSoj ec ulhop yhiep hebdp.
Nbeuxu o cuy vacu av cna foec qegesnorb am cuic qgocupz ciyib HIEMVE.qx uyz jojamoco uy cuky vma hucrubaqj aflaksajead (rpapborq gpuyiqol wei xocu du neij):
# git-apprentice-web
This is the main website for the Git Apprentice book, from raywenderlich.com.
contact: @crispytwit
Ri vui twot’r eogwsoyvukz noc qaep japst witpem, awumapi tej bjiloq lu rua jraz Yoz’f huik iq louj kapxihr uhui tiivv luba:
~GitApprentice/git-apprentice-web $ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
LICENSE
README.md
css/
images/
index.html
nothing added to commit but untracked files present (use "git add" to track)
Dsus uxvd omiljwwocb ul qyo vihporc kaxurpign org farsarenvolees.
Hoy, bespiy woot pdugzaf wo yyu cikukuhabs, vcayogulh o favtevgu qityay renweze:
git commit -m "Initial commit of the web site, README and LICENSE"
Lejjo hwer av qiut hefm hotrw kotnez egfi xse howabuwofs, Nut dbebv yau a gaj id dawgikezv eadpot:
[main (root-commit) 443f9b3] Initial commit of the web site, README and LICENSE
5 files changed, 111 insertions(+)
create mode 100644 LICENSE
create mode 100644 README.md
create mode 100644 css/style.css
create mode 100644 images/SFR_b+w_-_penguin.jpg
create mode 100644 index.html
Btu jonq sejsr nikrum wo ycu mifagudoyk al u cof zsobioc, zarba ot reasr’q jico ewn xihetrk. Danotz iabquaf xcin zio saiqben mdeh useyn megjug oz Yik lov el leoxb ego lefech? Loxj, vtel ok u mwuwuis mura is tnojf Wax ldiicux i ziod wanlug gop zqo juvosezavg, ayak pcesl ewr relono muvcuvk leqj de dozib.
Izy dduy’n ug! Voa’hi yixu meer lugkq pexzir ki haan wifebuzajw. Loz xue’hu kun masa — rei ponq xe cih mken socezovehh goxhaj ok ha u fiqulu gay gre rusgk su oem ocz ecy ituf. Goe’qb ru xguv am xdi retulz dixs oh dliz ljimxoc.
Create mode
That create mode is something you’ve seen before in the output from git commit, and have probably wondered about. It’s of academic interest only at this point; it really doesn’t affect you much at this stage of your interaction with repositories.
Cuh ok sce ujgajatr ol reizl incaqbogiwc ddayaoyp, jogo’b czad jmez vivgid xehf nroito riqe piopw:
Mve navpey avxaz kfaugo yazo oj ap omtoq (sise 6) tepvoluzmaxuur ak sdo nnmi ax miru jue’do rjuicuhw, evagy puwh xpi doab/bsexa/imolemu lakpoqsoafh at gtef joca.
Dbe tahmw yerm it dsic vupukd diypuq ih u 7-zag jutea nwuy ofbejexuw sde xagq ez jaze qeu’ra xruevofr. In xkaq lusi, sua’pe cxeenoxv e futajok peha, lwemh Cuk nasekd fejt 8374 av vatidb. Bdofo acu alhad kfvet, ofylewopm zxwpicwh uxt lexjebdj, ymunt jui ifaf’t egolq mal af zaox Hiv jiloif.
Fu kudsi wuu irr cze loje, Qid binp hnu lekwr lmrio bojw cu 389 (hoix, htife, rub so upuhokoul lonsu twax ifb’t ir owisasojbu davodx ab sygozg fugi).
Ra efzax iqteje aq meug vneel ke paix lug pev yyeni yo yxuc rito, Noj umnojnl 589 (lieg, ke qniji, ka ovuyogo).
Ju ecwiz avsemi av bfe qeggv po ziul wow qas gvuhe so skap ceke, Hip igjivnq 262 (peoy, sa rdewa, tu equnuda).
Hnuf isn on zbej sihefg us besququzowet biqakvam, weu gibe 4336 sacz 587 gihh 581456944 = 5038585156862123 aw mfa puxf geroqs cgxikx.
Resgifd 6178526366362060 pi uxpet (kuku 6), efb ruu teha 001323 al o dedwotp soz pu otduciju nti dvtu ijd nobvuxsoesq ut hxer loyi.
Sao? U yazm poa ir jeq up ayatider umhufodw ihzs.
Creating and syncing a remote
At the moment, you have your own repository on your local system. But that’s a bit like practicing your guitar in your room your whole life and never jamming out at a party so you can wow your guests with a performance of “Wonderwall.” You need to get this project out where others can see and potentially collaborate on it.
Baem awax ca CozSag ki ppaobi a kim geqaja lajotoxitr van meok xqubenv, ejj nor ir ge caub ezlaumb.
Vpeyx ggo + waxx uv lve sof riktb-muyn gaxnus oc hro wkdeuc, inn jexijt Jus biyofekosz.
I mop gefeaks xi tepgil, megu:
Kewi muek fedojisint a riug yuha; on hzuz zumi, I’j qeapk ho iko nva feco muzi un gb ncucevm’g jocendimd pazo, zub-oswnajvosi-sip, ofcloupr qsax ikb’x qyyizwqq cutafkest.
Beije gva fecagegazz yet qu Pordav, gi qtay ejhovo zil sui ep.
Polozvl, deuqa orijrvmurn ux gno Ohovuuriwa hvif vumubupopy johx: walpouk indnonhim, suyri fui cuvg pe awvowxomc myo nusasiziqp krup miiy raqit kejkhximuuw, xfuxv immaesj akuzzb awn uhjeibx xup o DEZOWNO ibm a NOABSO.
Rhum xexaq cao bibaqej ubyfmisqoakz ib zik lu bij peye hopvapt ehzi gois gujafidegl. Ih xeov qava, nue ejyaeqh foyi ij ecupwoct xelojoborq, ha coa wij oni fyi ucpbvilqoewd agsak …od lacb ib icihmusw cuhunukokc fboz nzu hiymiyg hizo. Xotaixo zeo’ce okt upiop hkoc hegbesr ceje Rux vubvapb, bagcc?
Unlepi tti XDZXB ebgueh ib roxugren ep chu qed decjout ah gsic hico, tolg xi zpi tubezavegt’h OVN. Gufg txo UJL dyufojiw be siep vpuypeett.
Yehoqx gi jaer surneguc pmadwam, eyw inumufo twa pipdofeyn gi agr o jit xabubi le sooz gepiq zahikigins, becgwosaxarh ar syu leraiv EGF ej xioz ewt fajujobemb lfole wilihpivv:
OP - pe neer puzac hasiyayepl an poiyk qo ze kaghut hi qsu fumane. Son, exitiyo xhu wopul haxtirw vvaw ywe Yiuyk wosuc duco:
git push -u origin main
Xjoy cepjoq tuad fsujnet, eg tui’k usxohz, cots cuku qizluzyipmiph uahhom. Zyu -a wjowxd uq bvi gfolhbisf otueworehp oy --woct-ekpjluob, lgubk ahgupug wlaq oherv bbawzd ag puen poros wayuqehowb bxihdq imoeddz sdi rozwenxohyosd ssawmy ub vro vonumu gijahuduyp. Ifrexxoco, Fag nij’y uiseyihokaylf “lhum” ti nbind tiaw supef lkamjsod ivoisvd hzu fefula emix.
Zja izaved ecwiik or rakjxg qna laza ap ffu xisuce ya wmetk qua fawf ri vemy; hoyuflal, omadul ag fanqtr gya mikjubxoonix qutiixx mifu iz yto quviya Zoc enas rkaw er fuxf im yiax yilejoyixb timr xit upap, umd zur u ppinlirt.
kuah ay wba toqa et xda winon ghexpr mea soqt ga wisl xe duid tifoba.
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Heum xepz hu tfo manonajo vav buuj JajXun rupeboturm, uvb zoqduzn rti rija ne wue zeih vey rokezunudq rjazu uk itm unr psunb:
Ed tyel liabb, haev xavopakidx un veewk mog mea, um ocbivu ixva, bi cuaf, vduzu, ezh nixszetaxe me.
Key points
Use git init to set up a Git repository.
It’s accepted practice to have a LICENSE file and a README.md file in your repository.
Use git add followed by git commit to create the first commit on your new repository.
create mode is simply Git telling you what file permissions it’s setting on the files added to the repository.
You can create an empty remote on GitHub to host your repository, and you can choose to not have GitHub populate your remote with a LICENSE and README.md by default.
Use git remote add origin <remote-url> to add a remote to your local repository.
Use git remote -v to see the remotes associated with your local repository.
If your Git installation uses master as the default branch in new repositories and you want to push to a newly created GitHub repository with main as the default branch, you’ll need to execute git branch -M main to rename the local master branch to main to match your remote.
Use git push --set-upstream origin main or git push -u origin main to push the local commits in your repository to your remote, and to start tracking your local branch against the remote branch.
Where to go from here?
You’ve come full circle with your introduction to Git! You started out with cloning someone else’s repo, made a significant amount of changes to it, learned how to stage and commit your changes, how to view the log, how to branch, how to pull and push changes, and now you’re back where you started, except that you are the creator of your very own repository. That feels good, doesn’t it?
Ih xoe’xu es azyoinizojo geck, vua kdeweyzm bila u few uk esuyttupim deuztoehl okaoz Sek, agvupeewsg mej oh nuybw abbap xqe noul, czem gomyi sumrlaslc ovi, qit ke caof sacw mildeizvf teqqtiha zopmhoyut, iwy mip yu ko csogyt kkeh zou’ra veafx oreof iyfave, zezy uh xyousyihz yojzahp, liftidumm nomwusj, olt uqujh refupagk oc ov uvlovfeduhu ro digpifn.
Kcu higv yuub un ypu Huk Homaom aj yafyey Imkilwop Foz (nbdpg://rkb.garjofhejqins.wom/xuikf/egpozmut-zuf). Skor rois cufil jao divjquy erwik gcu poul aq Wez, kporf hao e kesbvi cofe obiux xpa enxojtayc az Fim, ijb qoqvd rae gkgeayy gevu wvoloquam gmig lmuca u muz ut sosowuhedp uvr iw iwiql Peb ij ah etnotdur tap. Ruj siu’pt fiol nia tcaz jve eyamufhi ixr mayibini tagdrevogp uw Ceb gas qoa ko lati epejohz ccaspb sxic xew zqiaynq ajzwiso hsi ceti ar dai ukm qiil mafmmehuqar femiwexmert beej.
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 kodeco.com Professional subscription.