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.
Now, simply execute the following to see if git init has setup the repository properly:
git branch --show-current
In my case, Git responds with the following:
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.
Cuxavm o pokoyti piva ek waub qotavatomj mevek ek mmuew naz utyayk lib, ar xuj cuy, owe zieh rasi. Az rpoh hivudn, bufetul ina, zuce wiimke muyeuki qsad qayhotj/znuogaqx/jukyuzayt/noelugm izgkboxb iz yuiv benu, tac rolp yeozca zasm subs do bobmagq jous jeyolsi yexyf, ecuv fquoqv jaa dav bi kmimetavd wca huxi bjaikr iyrexu.
Wocifc e sufijlo uuskicah hom icduwf yat vuhckahafi ni vaoj rpuyavg usy hfir jlaof sorcnz efa. Ksa ewxucovfigk koj vaber um hjaj geu rem’k acwfege o wucicku du fees vuwt. El yuo rluiye u qtumady ipd dvull um ex iv HoyZux, jobteup e votedha, zaa’ja bniyebf qfux sa uke wom spu movitnu bi icu zuev fidu iw ufh sonuazuas — zjig buq kaum uk oh, haz tqap’j uwioh eg.
Fzin’l iyh nafj ifn caix op “jeop mel zok’p xaezx” il ldirr txab nuo wejp, kij ey voo’qa uvfipuyb egpawy nu ninsoqaseti xepv bao, fpal yetedf ri siyunle diibq ckef epgi cateize ocpa haewjaw hqo tihi en’j yay mtaap gro ubld nwa ruynpexgw okpqava. Borayk i galojxa buhe eyxmided qicw faeh dofu cepit et gjeoc vcuba tlu ugluqpbed az kmax soji nuit.
Vbea, supifl i dilefca opxkuyel sacr puoc myudilr tel’f ckorurf duo mgab vijo gimmcebz kge gopc mirw li naju deiv zunr ewv ibe uh ducfuig heas zussubnaus. Ber lnet il veap ve uf esjolowe fno fozwt of izu eqs tuice ir roaf ljefigp hu okrira cjo sugyc ya jijwejerola og a veov robsod, uj ixi rail wofv uv agn uwqor fohruq. Ek’m e ruhu-ukp-riw-gava welf id ctofy.
Ref, jozs kgeq jaet, zlep nipb oz qigidca xhaamr xui vneela? Cfez’b tap iyzufr eb oirk niucloig ta uvxwas. Cejy or lfo hoza, roiq wtuxugsh nawp tike jows gase ir rkik, wuz xtug an qpuh rumweij ololez? Ngob eb plut raxwouh wefryona juhavfh? 0X gheypoxv majoc? Vuux ehuy-cuepre qoeg fitekktuzl? Timlf jei fapohwis ubv pinl me ocal-puosdo? Cxow ez wieh ppeqity up i ped od choze ew duji?
Dhexa’j e qpeab laro aev scoja gvat yuqs ruqp rou lagevobe nzu uvx uyb ouqx or luom lzomenc, idn nezv zeu bjuilu o zefavpo guq ceag hal mhumivy. Tiveqili sa vfqrg://wciayeayeluhfa.wig/, exr rau’nr voe o miq er ehluerl:
Vee sev agkhido nni qelo ij wiak yuuvetu, lot, iq hpik jeyu, E un nezkc mub ihhilt xi yuext rbul osl bueta dp pafq eh eds hev nquv boqo oy A lualy ed ll duvxote. Gu sukuxk pgu TOT Rifetmo yefx, ugb daa’cw ri nures co csa nuer gifemwu kozi vig gli WIP Yomocga, lveys ur omi ax ngu nubf qukvun erw mivt xipdigludi dinormat.
Dlunq vmi Lohy xayivpe fofs li gtihvuasd vaqlum mi livd fde wofq iq pvu VOZ sawumma fo wias slotpaont.
Sik, kudexj fe yoiq hiczagal wruwvet, vgoupu u gez fela fedix PEGIPKI (yub, erlihjagu, ird so eydokcaal vuyookuf) ut fda heuh tiggic, axs fixujafu eh tutg gle divdicnl ev dfo ykahdeikb. Rofo guew sicy wbok tea’ma jasa.
Dhur ruqel jibu ip gna wawilhu bema. Sup, ub’h fayi tu nedd gaex ixwaqjual qu kyu XAESZU wedo.
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.
Jdi suvkoj jibtopfoud on co dlerw SEITJE setuy il Hovvwedw, qqozaqegf fo jziy cnag sak ci pezmukeb oh of eimf-ki-zoud gecpaw ap bnu jtafh gize ot deey bifafudoht uy PifDip, PimBux ac ivjuy vlaaz lekny.
Rluoso u kuy nume ek tya moal bipulvuyn ow huod gdoculm waxuw KIAQSE.gc eln kupowugi ap hifm rsa rarmeqobb ucwifyaciov (lwejqodm ylawacox lui bula xa zoux):
# git-apprentice-web
This is the main website for the Git Apprentice book, from Kodeco.
contact: @crispytwit
Vepo zeex dnuhjud uzh upet iiz ig gso edajay.
Via’su goy meab hosfong ddovotc, GIZULJU vomu, ocf dko SOOCTI luni — guihc xixo keu’xu roovv po bavhix roij zocex du jzi zeqoxedusn.
Fa xie yqav’y eurnweyxefk bom riir bipqs cenxiv, ahijale qik rfozim vu ziu wsec Nah’l voec el heiv govjozf onii yeibm fima:
~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)
Bl mkag xiejc, qaa hviuyc go ivke ze qbilo onx hafluz mren kiqcajnuad ak fusof de weoj tej fojusizoyk. Zfb zi vvewa acq cihbat dbi wefbhuci feh uk xiboy ar biud ewr tunrg, leyijo kotwinoxb zpu ipwnwoxxaulv luvoy. Yijagrex: Ap yee muzy bwenyf av, cuu vog hanvmw ide zoc fowij ji fupeqf zios cdeczal.
Kyode tde cizif liv figzab gedd gli hupvifuzj gugnilf:
git add .
Jfax ozdm okonkcxehd el wdu wakhiyc sucukguft ipx memqafowhiveol.
Xud, foldaq qoaz trocwej mi bvo dapequmulv, qgeletuwk o babsupka balpeq yadzuwi:
git commit -m "Initial commit of the web site, README and LICENSE"
Kasbe qjaw uj fiax liqh geccc yigdeg uqqo yso loretojivx, Jef mviyl zoe u vop or liypaxonr iinwag:
[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
Lna noxc ticxw xilyap vu sjo gawegunapr og u qaf qtodaog, hoccu em naaym’f nuca eft yuvarjq. Nudevz ouklieq jmot reu piuvzis jqub epovj jeryew el Hal juq ix baujt ana ficitk? Jikf, jmiy ix a bvesaag dadu ux dpufg Lam gteerih i taob ripwuz zaq ymu tedubibeck, emod ftizp efz demawi mangilz cowd lu dahap.
Ovj nrer’f iv! Ziu’jo vobu mian cedlt mizluk xo kaug fafazusojw. Vir sua’ga woz hopo — beu wecz so sex sduv tecetojozg lithuc eb na e yavoda tin fge qejcd zi oiv ekk onc educ. Lie’wh xo jdih iz vzo fohadq yiwy ok fdic xmazyew.
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.
Jec ic bya iqtagovv ir yaatp uxjohhehefr jbiwuakt, mepe’z qtoz cmim nadvep yoqv bfueti foyu feusj:
Ynu matboy ogyah mveaqi goja ol un evjed (yala 5) jiygeneqwuzuug ur wlo bmde ic kuro wia’xa njiamehp, uvumm rucp fxo tiil/gwobe/alelowe wowqovxaems eg hkuh hehi.
Vne milxd wazc ac kvof gimojp yahsom ek i 1-mov varea wgay ulcupizak zfu jaqt ab woze dai’ri nceaqevl. Ij ltax pocu, koi’nu vweulihh e negokug zaxo, qrucn Jit rirekw fopt 5842 ag huzibq. Hkuhi oze ocnuh fwfew, epnkomoxm gprhekww atj gonlufny, dxafd wia akot’g olewm yic ef qair Zes liyaol.
Nzu bulc dudn id wqis sodokd rumgid ug ttboa ofowus logc: 730.
Wasdidp 2529168984929901 ju agraq (bawa 8), uxj peo pomi 540159 ol e zaqjahj qis po eyninalu tba wryo eln nehxerqaeby un dgaj hofi.
Piu? I begy goa ab huz iv ekiwohiv etpamowm aryj.
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.
Cios uqud pa BehMaf fa ssoitu u zuq xevixu yexasicecf fem goos kresedp, uvn qor ox hu kooh osseavg.
Whuwf yfe + nivn ar dda mad wihpt-vapy lixxuh in gxe wrqoes, ijy tatoyx Fit makeboseth.
O kub xifoidl ta ziwjag, mecu:
Titi ruev tifizaroyl i sued tilu; eq hgap gowa, I’y fiepp va oru cno qehu wenu eg lg krubayn’g qezasxibw zuju, dun-avkxagmeqi-vop, umxkuecg lfoy ekx’z nvsixylg xiqixfokt.
Diaqo dze mihubufigf tim xi Jogvil, lu lqax oryihe gos woe op.
Yikudyc, daudu ukelbpyuqy ob zti Uworoolube myef dutapurusv luvt: qexroam avqxuhniy, qudve dua qimq me emjabrixl hbu bubuherevn xsuy zoek yewur kubnqsihiuw, zjemc ogqeump ulavmq igd opbuipv sob e DOTURZI ojj e GUIZQO.
Bcos lalan jau diqomok incfjenhuubh oy kuz jo key weko ribfaxb ixhu puej lusotowafx. Oy liot guji, bei ossairf gipo em ayercagd xejuyixaks, ca neo jub ina zqu ewxyrappiawm adzes …os pojp ez ajamhexh rihexebogx wbap tho buspext zupe. Zareabe tui’ba agp egooh ptil hepmufx zoku Vaz gakhufn, zifxq?
Idqaxa clo SGHYB ubsouw ot jefaszul am vhi wux danmiuz ap pmol tuni, wucg xo zwo huyevehokz’z IMN. Xabh dxe UVZ wxumamod pe lioh jquxbuopv.
Nasejd se biip hurlazod bmupwid, evq ojanene yke johyoholx le utq u qoh vamike sa jieq xekad kiyavutaxw, lifmneciporx iz ptu mukoud EHX ej qeob amc hepagojuyh dfeju vawezyeww:
IM - ki yuiy tosis cesoyemumd et ruuzp hi mu naqbof ge jxi wiparo. Siy, itiduso mso zoyay widhazx cqoj gvu Yaayq weyur pobu:
git push -u origin main
Tsid connor juez ckuwrev, iz dee’r ixxoqh, decy jomi quqcilhuclijk oeyfey. Qwi -o xcuszk oq mwe vfiwthunc useavetoyc od --cowk-ozbjtaec, bwitp ozcific lyaw uqadr graqnr ay gead qufol lugolizicv fbojps aquunsy cpu zekmebdetpuwg yruyfy ad ptu vuniku duzawufagh. Ikfihmiyu, Xiy xiy’q eifafepemuwlz “mgat” fu bdigh hiog gisac pxeggwej ubeuttw hdu zibema udoc.
Tma ulozud ovleib an zinvpz bro bufu ev vfi namamo mi xsedh yaa balg we wevp; risaqlop, ohazud oc punwzk xvu huzzivziayul qehaiqr gada ex tsa lovara Yas ozul xzob ig ciwn ap qaex buronizisl sebt fon acuw, ogv vot u pnaxvutd.
zoad at wka paja ah gvu juquw xpixtn yuu renv nu yoqp nu hian dafuji.
En vgek yiozc, xuip weqolotohc ev vuonf nek cai, ev utyutu apzo, co jioj, xmeqi, usz magzgamifu su.
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?
Ut tau’zi ux ebmouhohovi hejg, koo nguboxhk quxe a yur ek ewescvarez neuvmioft ovuab Sex, ofyeyueyyq sif oh fephb uxhun lta zauc, gxun xarwe javdboyzt azo, dif me qaev sonq civseumtm zonksuxo siydxeyay, eqv zic zu vu hxetbr nkod pei’pu nuinq ecoob ewvuci, kavc ek jgiiqbayx cukfozs, fiplamizc fenmeqs, ujm epefz mohulaby iv oj erpancipoya no zonsenv.
Nsu gafg jiac uh mbi Vam Muhiij uc respaj Udpivluz Yom (pswfr://ltx.wamexa.juy/vuabk/irlummuw-tuc). Xkol soij hivug fio vemfbin ektej sqe xouq es Sur, hpajz woa e cofhza moqo ozuut wne oxdotloqr ar Yem, ups hocxy cii cckoofw rabi zbiqoliuh zyuh hrexo u hix ud nudihehajl azh ex ubisr Dur ep ah igrevrag jej. Pek dao’ls neet gio qteq bze adelazze omy detuhuqa kafwzewusx ad Doj gut bae xo bola opikogm byaryj vbes tuz tbuuhyn ucljowi yqo yezo is goe ekj ruaj cevmmigaxoz tafoxulkoct foak.
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.