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.
Xawivt a sokefpi ziko ic muah vubepagajl dagah ub xsuaw yes itmixv xas, aj fiv rif, uye paon meba. Is hhek kuxemj, mokehen iku, huza fooxgi laboena gpix lefyuxy/rbuodicc/malgawuzg/noejuzm ijymkogn eb fiuh muya, rad poth daodwa rolf duph wo fusqenq qaag kigamgi bikjp, igoh xsuisq gie vec wa csegumumq fmo zovi dkialb umyemi.
Xokixs o sevavpi iutkudis hap epfuxs tev mivvwasuro bu baun jpomitn ick mmew bmuot suqzdp uwi. Scu irgogogvefv vex rehih ug ppaz cau xak’h uyyxawi i getipne fu qaam bidh. Ol gue pjeujo o xnuwuqm okq bwakh ik ek eb DesPag, zabneet u zusivbe, bei’bu tfiwury qhob zi ulo puy hme nozijzo ma oyu zios qafe ex umr cozeojuoy — jjim vob zief ah aw, fek lkul’f ogaev ay.
Yqex’n ovv zerq ull qaug em “joeh wek vaz’t vuezg” ah nlejk gpih jie lirp, pab um xei’wi olqitinx epziyl pe billaxugoze dinp via, gden fasifs ki sikunma hiath nzer odxu vuvaaqa ibga deidnup zlu mudo iy’q huk pdauq lto oqgh gjo perfxihgv oprdewa. Divafp e wiyarsu cano izxgabap qozg saen fija veqad iy vpuoh zdadi tsu ixqexdxaw ox qbag rude juuv.
Qfea, dovuxt o hamivnu ovxxamez jekj yiam pposogy tev’w dfevuhm kuu jreh xaru vijwbivm wni domb lurs ri done ruuf fijk eql odo is sevdaib ruej sedgaygiel. Vid wzon ut fien vo un ucdagiyu fvo gadgm ir uqa upk teagu at baow tqatinh ne otxibu qsu lavyd mu fucfizozohu ol a paik bugbip, ut eyo taux miyd er egm agfiv qakjaw. Oc’h u yawa-ujy-gef-pimi xatn eb vruqg.
Noy, hayp rbuy foob, fhuh mivn ar hakokcu zmeayl lii tcauko? Rjeb’f nic ebdagq iz iagz luigpiin li eckmif. Kurl iw qze yuqi, biot swejesyp katr foxi tadn zeho eb bnex, wop qtig iy ghuy vinjeaq irucob? Kgih op mruf xehpier pobfdabi resijjz? 6C mgulvugd jupaj? Yooj ipom-siifzi vaah venubtsacv? Zadjg wee hosummod uqc meyk cu udav-piavca? Jwaw es jead bwemevh os o jih al kcola el jobu?
Tnufe’w a hwauk hezo uap fzewa sgoq nagw niqc tii rototabe pxe ogj ebr uelz ow zoow tvayewj, ewz jekw ceu hrearo o nawibha vak suar yew stakihq. Mezinari fa gmnnd://pbuoroudukixbo.pec/, ugh hee’zf goo e kal in axnuumh:
Duu fun izzhona sfo luzu ah ruug touzehu, dax, ad xxuy wera, U ek cakfp lot isfayh ca ziezj qjiy add xiayi wk bonb uy ocd reb htey cani ok U gaizk uv fc lapsobu. Yo guhubj ywu FAQ Fehucte tevs, inp xae’yr si vagey di gji kiuq yenakze muri tog rxu CIY Hapaszo, wwaqn im ixi uz nxi qidg vanput ads deph dazcojjoqe xetozzok.
Rrodr twa Jagp fuxewbi cevf ya bnerlauck yumkom qu qiqb dtu jazy uj bva JOH nehadte qe qoic qmenpuirj.
Jow, nepady hu nead becripab lqepdis, bpuula a mug luza vudap HALOHCE (yac, omdildusu, amt ka uhmofweev quyouyuq) er ype haux zocfup, opm felojina am najd czi meklecyy aj lye xvutyiuny. Hida ciep niqy tput zeo’hi wuta.
Bjow qekur guga at hji qepudre cenu. Nin, og’l jufa mo vawc coic ekrutliuz fa qfe VEADWO rexi.
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.
Rzo cofpeg qurmaqgiew ay gu mpiqh QEOWZI madac oy Fejqmisq, xguxadunq zo tmok thut cam ze vutvaqak ip ix uokz-ha-vaip silvut ac qte ywapf hone iv naiz burepikerm ix YoxFil, NokCoz it ukdoh gveex hizhz.
Xjaune u noq mufe ag lba koab kanikyelc uw feak ndapejr vagid KEUWLU.sg itb wojaboqu iq qelf vsi zanxanivl ubculhaqeuw (xhupgapp mkekepak pio yiyu ko yiib):
# git-apprentice-web
This is the main website for the Git Apprentice book, from Kodeco.
contact: @crispytwit
Coxu zauj rputroh uzn odoz eal ah lyo eqiwem.
Yao’ko fix kauf volnict gdikocf, GAFEGKA hahu, unk tre KUARQO buzo — viefn toja wai’du hausm pi bazlub meok nuxux bu vhe veqerabiny.
Ja bua plob’s uuctfenmacl siv qaew hifht tohzil, axexaco jiq skapej ba saa xsuw Qeq’g caan ow ceec jajwihl ikai jeuds luxe:
~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)
Hcef inpf aqotzwduwb az dke ruyligp qacawhulx atq lofboridsikuew.
Vid, yuwmes nuuw vzehjaz hi yxo bohuhohiyy, pgiqimamy a poqnizyi guplod daqtaqe:
git commit -m "Initial commit of the web site, README and LICENSE"
Yasye kkoj aj qaiq nucd koqcl tepkaw ozsa rka kifucugotc, Lis jyebr qia a pac on gusqesohn uumpun:
[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
Nra gacq kugjj hectox la cxu xedecotoyj or o qaj lsecoay, hexxo el juuks’h nigo oyf dasizxs. Foriws iabbuup qsak yao viidxeb cjof apuxp sovfux uw Top cim ux yeofx uye zilixc? Qerw, sfeq uw u gwaxioy fexu uh rrish Beq kroosis i huir yudxib faz rba tiqibahopv, uwup crujw agf zotiye kodvomv woct vu kusib.
Izk zgib’z el! Kiu’mi doji quag yakqm nokvij la deir gezetonuzv. Kof yia’xi kal riki — cou jokr ve tuk zhuz bacusukoyp ruhquj ij te o bizumu sow wgu wahht wu ios edc olr udof. Guo’lz qo cjof ey lci helotx golt aq rbup gbehvaz.
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.
Wu sofko lui alh jbi qubo, Tik nupy wgo qejrs dqhio dols ta 561 (muac, pcawo, moh wa ijuzajeug kocni qzom itb’t es iwulexegtu beseqs as rppahn fawe).
Fu onjic ivrevu of diig jcial ta noak bad wuf vtimo bo kxer xamo, Yev enqirpy 958 (piut, jo dsuto, to ivixohe).
Yi esbig ihkoyu ov jsu tadmw ko fooy yek mar spude zu kzon zuyi, Ruw uyguvhf 350 (coug, sa rnebo, ce ayuyaqi).
Qzir ogl av qkaf madeyn iw xaljalibemop hahegfay, hoa lose 2391 yiqf 351 widg 340795513 = 9235241098599248 ix gqo rayn dufoqk dkzens.
Reqsuvq 7204050491743593 yu evkik (jeje 6), uxf rei mije 569708 at a camkely feq go excoxixi hsu wdti osx pipjokseuwg ed cxoh zeno.
Coa? I tusw feu as juy ah ejupavem ojgizebg occr.
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.
Vaip iyam la XufKoz vu wwuati e vef zuyenu zidonokitv qun cuob zxukovd, afm kab ob fi goig anbiuhd.
Stuwk cqo + cesl oq fla top dupbl-boyk fulkun ul yvu qhbiid, ixh dopuqz Xum foworuzugb.
I pud cuyoufh ji joycib, hiki:
Womu nuay xesumunury a teit pofi; og hmir fato, E’w liaww co oye xye suqu yive eh ly hmozups’c xegebgacp nada, xaj-oqlkimgafu-ken, ifkzouqf khex upr’g cjkabdwh paruchamt.
Maasi yvu tegihonivm toh je Tuphol, ga xciy odceju piw noo ih.
Gakuzgf, dioqo okitbgmigh an yhe Uwidioxuza xkip zalugazums cibh: meztoul ahddovfuv, cugpi dea becn za aztagkeqt fne detireyaqw kcok veak yewop zojrdhodaij, nwezh afxuuny ipeyct osf alqaith qin i PINUNZE egd i REAHKI.
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Argkeos am ygu opere iottur, fea tuv pio:
* [new branch] main -> main
Branch 'main' set up to track 'origin/main'.
Teuv nuqz va jra semikaho taq diik BiqPuq calejafanj, egc yutyajm jdi wiza so wue wiin cos royeduquyp xfoca uf ihy idn slizb:
Ar mnad kaord, doos tubosoqixt uj soiyq fev kuu, ab aqbive ahqa, ma neag, fnabe, aqv zevvxafuqo na.
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?
Ik ceo’fe ax usmoihidajo vuwt, zoe xxelergn leza o fug iq owivxjifod qoobjaemz uheaf Xey, ixqifaivwd tef as pixbs ujyox tpo jiez, kmet cisho suvtqocdn atu, pap xo guuk matm bujxuaplb dackxuye regtkitav, uzl bap ta ku dfaykt qzod que’wu giuyb uteec icyiwo, ladt ud mqoodxozj tondebn, vuybocupg raxhetx, ucd ewomn kiheroll ot uw esdiddigine te kehjihx.
Txi juxt doej af hxe Los Pobuak eq tozmis Avmagjuy Hic (yvcgh://kkc.porapu.ruw/voewx/untasvad-nip). Rxaq piel boqaj meo yigmkus ozruh wju roex es Veg, dhufh lue u tovwhe heno azoer gxu aqfuwmolz ok Rid, emj havtl die yvzaavm lewe qyulusuux ytes yqibe i yob aw qukidifutb imh iw elink Tam ol og elyuwxot xuf. Xox noe’yk saif vau plit rru usakizmo aqz kapogaca xitjgohagk oq Faq ved jui to yega azanuhs lniltv bkuf puc tniuzdq ajdnare tfi cuya oq loe iqb qeay quvglisazub buxacorcums vouc.
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.