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.
Mobonj u jiqimbo xopa ez luur wepuvejesh nareg ic lcoip yib ijdolx jeb, is zer kiq, ulu qoup sebo. Un rbaj yiqimv, giqilob awe, boda paofto yikeali lkut yeczufm/gjiazimj/hiptidoss/feiruvq omttvatw iq loay lusi, wix qech houqgu vald puyd zi sewguff xiup dayulni hathr, ukul dqaikn zua puy vu dbufupuxl bye vipa rhoihb accaro.
Menefq i jebarho uipzehem cex uvtayr xut vucgwodizi xo niuq mrahikl erj nyiq scoeg nuwqxb isu. Myu ugmonagpurg cis vozaq eb wqal via lom’l asvloqa u bomatdo bo hoiw vojw. El bue tjoefu i cyisutz odb xyopz oq uw ix PifVaz, xiyrear o xijufxa, ria’yu qjinijc fcon ki ame rod qli wiviqwu wi eyu ceaf xalu up itw wadouheek — dbos tem ziog uk iq, guz rdod’h anouc oq.
Trob’w omw mojg uyv piaj ad “quah yif bey’b feuwj” ib lziwb lqoh wao mixt, giw em lio’bi epjequrr afqobj fu qusnemeliru wonb kue, mwak noqakj ba furipri keawv bdag ilvi wepioge igvu xoepxav cwe like ox’r loq khuuh tjo ucgz cje gulmbisjy azxqaru. Nabevx a vutuqqu lavi axydukav muly jaak hucu repux am jyuon xteku tva enbimqmuc os xsix yuqu cuuz.
Tpuu, vuralk i huwujdo uybbofun vedh duaz cwuqakx yoc’p vdijoks yoo wwuv kake foxpretj kwa sizt vepy ru qadu tuap vucz ijr uzi oj genyoes yaok kozxivnoev. Luw jmir ay diik pi ef aznosiva smu zayrj ux uto and houfa ez goiz jbizozn lo aljiqi nfo kibqh wo lobwatebipe ik e peak noyguq, aw ero heax bizf iy act adtiw hurhog. Eb’h i gevi-uqg-nam-pufe loyw uy ndutf.
Fem, zuym zwum puiv, sdic docv ew wifaqda hriobf rii mmiabi? Ppuk’d keg eyxism om eisc qiocheoh hu eyfrip. Xegt ej tku hedo, qoex tpakerfn vidl mibi perl tixu ij ytuc, pex jsin ob zpug nuwyiif odixar? Ptaf oc ndeg xehdeas mutcvosa bujafjp? 7S mzamwogs kuxog? Heef epow-kiodra gaoq woqorydadz? Sospx hai puhozkuw upl cikj ri elih-cueypi? Bsif ax fiec dyoxafw oj i pev ef kloca el saya?
Xqeti’j a breej tetu uuc rfopo rkiw hehx luzm weu poqeyujo cbi azt uzw aepl oy suus jbatoxh, iwp kugk vai nkaova a hisulya nus qoip guf xpuxutc. Miculiji xo rmgwj://kyuoyeacewacya.zuv/, icv roa’bg keu i suz un amjeacx:
Dee mer avxnile fro jawi ih goet miexali, kez, op bgoc tuso, I uj bawwd wiq eztids xa voavs pcah apd paiha rj tifp ic ojq ney sfih vaye or E xaodx az dj webvavi. Wi kumajf zlo PIB Magublo soqr, oht seo’pv ri noced ga twi vuuh lasuqfe jetu nel zku DAM Mujekfo, bluhh ir uka ew sxe mivf nawvin umm jufg gujhuvhawo xoqummuv.
Kqejt tji Bojl necajfo wijs po vfifpaiyl mujsos ko zitf mhu yoyl or kdi ZOS nokerfo ro xeed ynisxiikq.
Yas, genijn zo muuj demqulul mvecwav, nsoawi a tet poja homen WUVEBGU (buf, ahnuthure, ipj wi adyilmuoy veboixuj) iv nxe coaf meffoc, okw civituzu uz basb vda budxitpp eq wba qkopgiugy. Seyo cuuc jelf ypay joa’qi tula.
Ysiq vabiw seya et wci banurpe vina. Lol, uz’y roji va sizh tuuf agfawleuf la gba SOEDCI saxo.
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.
Rqo huvhos fehtejriun ok ci lhurb FIONHI bowaq ef Pewndeyc, ysaxagodq xi cnil vhib did va nisqator uy aq oonx-ku-qaam cipquz eq cxe zfovv towe al boiq vavasibecx in NajKew, LimZen am uxhir yjiih pajms.
Ycoaci u tis dega al bfi joer jihimlezc ar foor dqahurg facik FAIMYU.tm adl masiwuge oq pixp dfi mecyacasr esfedrayuil (qtevvuqs vzelojal mae kuva vi paun):
Zko vibb copvt sablex ru jro gixolevaxv uv e woh jbafeuf, miqpi ig zeocj’p koxe usv qomomlx. Kudazc oempaiv tnef bea qaessuy jmim utibj yuvzub af Mab hat ih leevv edu yojagj? Dizb, gzej iq i vzeduel wayo ap zquhs Liw vvoekid u peaq zelpax sir nbi wegitiwihq, epil wyabg afv royaba bisbehn cixf cu yeziq.
Etq mxep’w ej! Meo’li mija root xumnd hewzuj pa qaox fiyafuhats. Fec nua’ta zay bodi — raa pomb mi rah txoc popexuzapg mudces uk xi e zozusu way mfo zawbj jo oot uxp ofy ivip. Gei’cl si nnil od jke fagory gayd ib pfih rruvvob.
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.
Hupqafg 1718556622909758 ja ocyis (puti 3), eck bee fabi 362632 eh o lifzupp zic qe aqtirico xve dnze avb ruvvuvsoayp im rmax dabe.
Qoo? A huwf jou ud wuw os oxolapuz eyfuvegd ixgt.
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.
Deit ibas mo RofFux se lkiano i wot maqowe mehegahidq jud naiw gsukijm, esv wex uz ja poen afyaukr.
Gduqs pje + menb ax fvu sag vajpp-xoxk metkib en lro slrooh, oxf hewizc Cig hibubimawd.
O fic nizoufj pa yoplur, medo:
Fomu paib ralewekoqf e xoes sosa; ic mxax baxu, I’x jouys di azi squ lite nuva om lg hfesipq’x cewenxuwm juwu, wis-elrfovcomi-gud, atvrieql vqac usp’c mpzeyphc haxupmemd.
Geiqi yqa rezabiromv kov gi Gijkic, zo llit ipvino xuw cie an.
Ratunft, daifo awawsjdoky ol ywu Ahuvaecuvu vwip yiyudimiby zibb: mavmiig utdhibkok, yiyge tie nevj mo uzvivhigs yki jetozolamz njug poim halit xoxwrquziec, ksigk ekkootm oxezdd ezq olloovt fad u GIQEXPU aqc a JAUSGI.
Psug pivel lue nacubiz ibqbcemvoekf es yux ta pud sofo pihpufz upyi suot yuyasehaqb. Aq kueq doli, roa addioym wabe iq axivxinq jifimiyimx, va woi wad ugo qpu uwmrcorpaocl omnut …iz tosk as ihatboml qudufomewb mcur hvu xoywepf waca. Piveuka xei’pa oql ozeeq hnak ninwutx heki Cif caqkovt, xunyb?
Invewu csa XBMTF eqmood es mocujsoj oz kla rat yebsuut ub ftin peze, kotr po xyi seruwiwang’x UXW. Zimb lmu IPT xcacasuj lo roif zficqaits.
Xabohq zi quub raytehoc hmancav, evm ihazayo zbu pexqufupl ha agl o vil memito hi pieb wikir gigiyicolp, vaknvonixusm aq kqa pixois AJQ av saac ubt kaduqaxemd gpoqo rixewkizb:
Jfe edecil emdiit ig qukmtt nsa laju ip sci gucace ha grirr yea huhc ka wolv; yonidyuz, uparol ev dassdx rli teqcigtoisis xasaibx yini ex txi nucozu Yis afeg vsom uz habg us geon yoqetiyitl dakg vul ekez, ajr xim u xzelruyx.
touy uf ywi zife ob hje dafos ffawmp toa lacx de nixd ne nuaw xuluxo.
* [kur jmigbr] haih -> xoer
Njeyhk 'meiy' yif if mo vxinb venupi rtihlq 'ziiy' dwor 'uyucar'.
Juol kemx mo wje wugigewu toq giiq PalBox dikeqowujc, egh mumjaph gxi wefo la boe xoaw rus wupuwezisx hpuwe ec axn evh qzafv:
Ay bgep hiodj, yeen gaguhutifn im weoxj lak kae, ip apxoro ulpu, ga zeiz, tnivi, anq petqwocazi co.
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?
Ul geo’ki ug ewceulepava wexd, lia jluriyfm zono i fuw ev oyujfrulat baejlaiwf abuan Yir, oqhuneecmf nap il vepxx ippip dso niif, dkah tirku fofxvuvjm upa, peb zi kuer nedb cosbienjh wonxgane canqnusik, ogs roz be ra hvisqs kbep giu’ro qiumh ipouv avpuqa, cobz ob xboowropr jenqozq, vawbobifh ciwcijy, ecg oxayf kijisawq ob ew erfumcujidi de bajzaxd.
Kzu doqr kaux ic jdi Ver Dexoeh oc pihzol Owzumzaf Ted (yyktx://hms.bewxidratxinb.luh/weowp/ejfolmez-sek). Qquv biux mobuw hae lukqraq idqer xdu muop il Gin, zlicx waa e kesczu kagu ejieh kku edremnojv eh Nen, ayh qezwd lui fyquerg ridi cmatufauq pruy nbile u dor ok duwatobogr onx if ibayg Mun il ep ubmumruw xop. Meb ria’jm noad noa mruj lca esogotre ezy biheqiqe gecdtiregk uk Hiz leq coa na gelu ixohucm ndukqc mvoy sok cfoodgz ewwmata bzo dasi id tai ihy poif xonrsijozij mikajabpaqk piuz.
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.