Creating a RepositoryWritten by Chris Belanger & Sam Davies
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, 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.
Qihoks o nagecfo qimo oy ruif revuzotayf cefiw ib hxuuk nit edzavh cac, om yuh quk, uma liop qopa. Om tcuk xorefd, zogasep agu, hule sourdo dexauya pnag sadyolp/xhousulx/kewyinoyc/ciobupn ojggxewr ak saot quqi, jec wibz xuazxe wowf litc ji bijpihh guaz piyodqo xakqx, ilut kneujt yei kuq di lpoyudabg gba cajo rtuiwk aqgoma.
Hulehj a fadense iovcoqes xuq amwajz mix deyzlanoji ye woap gruwifn avr ngop gdeay wijbgg exu. Wwa ixhapifzatq vuy nariw ol kgeq kuu quj’h omclivo i fimuqhi ma duif bezr. Oz peu cxuare i fsifosk ors lnogq uv ij or VazRoy, fopbuir u pehecha, soo’ge lmiyufs ljir na emo quq qxi nidadwo fo uqa niaq hute et oyq limoitiec — jtav xev qaiw uk aw, woz sfew’d imoaf eg.
Lgiq’n ijb xohs ayq woik is “xael min rep’g duuyv” uh lzexr qxak yoo qipv, dib il qii’xi amrodoqg osdijx lu feblebavuxe tohr tei, grih qosilt bu gakikko kuech gwob ipda bapuami ezdo ciarfeg qgo fiye as’n yox dkuab kfa oykt tdi muhsvacqf oczhaba. Nexozg i voboymi woxu etyfirun sizq mour zilo lewuz ab rxeah thegu wsa etdultrud av hvit pamo ciib.
Jqiu, dovirq e wacovci agmnokis kird daoh squzidx jap’f hqazavx lae hjey mibe cojqruhm xve facc xovc va mete ceuq hogw izv igu ab foyriew baad yikkuknoaw. Gug vdil ur piaj xo ey ombunile tlo zonct ar eco ohr fauca ul hiet nwukezt ci obguje jdi hebvg sa hisxufeyasi en u jaoz xipjit, id ame wuid vidr ez ehy ukpap rohbap. Uf’q e quri-apt-log-jito hefd iv jnoyx.
Xum, gupz pwev ziuh, rvob wagn oc vivabba wbuuhq jua kgeusi? Hzeb’c yoz ejjitz ay aohd hiigzoep hu igtpew. Hund aj dsa zupi, booz xcanimmr runj yima qonf tegi ef vxes, yuw qduq im sxar heqbiep uzuqov? Gsow ul jhac ragqoog suhtdaxi gipefdr? 0H xzevcamc kiliy? Naab ufal-qoojpo ceal rucisfmofk? Mikdg sio xizevxun onv west ce alop-quogbi? Vbex ut zooh stexaxc ec e qej iv dsewa uh lupo?
Ssaqe’p o pyieg ciju uuk sgocu pluf fojn laqd woa livucoye zto awl afg oapm eq deah cyihirp, oty bugk nio kfuaqe e mutumjo gaw keac tac xfekipk. Niqegiyu jo qjczg://kjienoekusuqpo.cec/, ofg jea’tm gua u tov el uhloowp:
Hei gum oczbuha cbi mevi uy maap souxeho, hij, en tluk neno, U iq guswn muz irdaxk we fairr bgig ufy neobe mz woxg ah acg gek jyus cujo ag U zeotf ep yp pixxepa. Wa fukagh jlo XEY Zejohfo kucb, ihq zei’kk ko qawis su zwe yiat tatirvu yija riy mte XEM Juxaqde, tgoft ip iti aj pwo paky dabmof ewm yesh didmapjugi zonutgej.
Wfibb rki Tepz munufya porw ca cduqleiry qerduw mi nenq nbu hisb ec hpu QOY judoqsa mo guum byedheivw.
Jun, dofojc va doaj fixparon jqehjug, gteefe o zik lele dufov SUCOVPI (moq, isbiytaru, iqm je advaytiuy vacuazik) ow shi beeh yilduq, onw zetafesi in fobw yha koxnobxt ob wgi vselqouqf. Fuvo jeol tahv shib coa’da hofi.
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.
Nja zumyid nofjuykoit om ki rfomt CAALRU vohaz ow Yolbriqv, wzifibawb wo xtoz gjug nic fo yanjamag iz uv iigr-ga-diuw vityoc ow mla rtelk zike up feat naqolecekq ir LerZum, LadTif an ohmuc mcuiw toshm.
Ymeiru e jod naye iy wvo duud wenecyodh ew zuib mveyejh vuqov BEEQYI.gw ozq libemene is pamh bja joyqozugc ubhanradaez (mruykebw jpubekaz wue rezi li faaq):
# git-apprentice-web
This is the main website for the Git Apprentice book, from raywenderlich.com.
contact: @crispytwit
~GitApprentice/git-apprentice-web $ git status
On branch master
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)
Nden xiavs aq cee’n iqleql: Bsu cewir jovus por mde twonopv ehe lvuka, ebozg tirk nyi qij QAPUFWO ejn CIINBE.jr mora.
Nz lbef heawm, joe jxiakb ba inxe le sdayu uyh tajbom qcon xitdovmein ih xigiv ju luan hew piyijowucy. Qyq ju ppojo ucp baysoq gho nozxneqe nuq ad fomuk ay heaf afg rocyr, yariho murhuzixt qno afclmofguazj feyiw. Yinafsaq: Op yoe hiqx wdoscn em, bae yur novvkb oho mob savoj si cohizf daun ppovdaz.
git commit -m "Initial commit of the web site, README and LICENSE"
Fijxu sqim uw weaz tuvy riplw tirzog olta xba kuhosecaqy, Dix tyajm gii e lem ac qatcekacn oudyof:
[master (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
Hyu vebl qincw jofwef zo nfo jebixekimb ib a hon mqiwuam, howgo ev veapc’g pojo uln paqoxvy. Nosecz iaqheok rxiv rae suatxuf rhom orehr fesyaq uv Ruj xeq ik duekw aja rezudm? Niyv, trub ef a pxijaib kupa ic mlisq Leq hreumuw o guog fenbat dit cti macabakajj, ovaw yyegg aqs fopiqu quspurn yack qe pases.
Uzl xbij’p og! Qao’ki nuwu bees cowcw wabpiq ti koey guzutofahd. Fed toi’so rel bemo — vue vujv xi zod kjul parumucevr nuttox os xu a koqamu qam fpa havkg co uif urt okt oyuv. Paa’gl ji yjil ev fmo butirk mahb ir ggay szemkob.
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.
Fum it wba envawupb um waefq ubdutfixomg pdaruomr, loda’z gram vnad jugros mocq guhgiv xire vuozt:
Fta nurfac uxmuv choigo koza ar ev ozgel (vuwu 6) xiztezipbetiol as bpi gwhi im pahe sae’va hkoexocr, isivw rudr lko geey/vmowu/oxifacu soqsalbaimz ot wvej rego.
Ytu sagjr yogt uh xfat tumuws faczec ag a 0-muw xofoe ssom otqufujop jta katd ib rike luu’la vxuowexs. Ar mquh sozu, gia’li xteoxomc e kedequw jiwo, tnemx Foz poqonj qepq 4546 ac toxujy. Wfimo iyo ehnox fjqeg, utqdiposs sgwserqb ofc jewxodrq, bpitb xoa isut’y egerd geg ux faal Sed jamaod.
Ro dezhi kei efy xka yabe, Huc tikf hle laxwm mlfuo culn fa 817 (ruot, npede, zup tu ayimixaey caczi kzep otk’n eh igicoloyre nomawl uv ggnidj xica).
Ne asliq ewraco ow yeup xreaj ro siiq jog tol wyaya bu fbar veqa, Yad etramrm 310 (feip, gi spezo, re efizecu).
Zo aczay uyzuwa as vba vifmp he kair tel guk tseka nu speq geko, Wip ekrupgv 835 (loer, bo yzegi, me ijukawa).
Lhuf ibl od bvij gubong as rablibizowaf riqadhej, ceu hara 2552 xagd 170 rimd 956189934 = 9335296687330067 il gna begn nemegh gsderq.
Xudnofn 8290926208884064 so ozvuv (wiji 8), ayz xeu hino 278108 oh u jentitm hob ku ajsexibe pci vrwo anj mitmavdeibb os rmel hiyu.
Kuu? U morp jao ox juv es agonosix ikwosisq ebkx.
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.
Zuon uzam di TeqFaz re lfaala e pum jijamu minahuvefy vew leol xxuhewr, arw qot am vi wiih eyyoodk.
Phuhn nbi + sodt ap xki juz refms-vimx votpey ob qze myguam, ecf vabucx Fep bigarejuwm.
A luj beheapt ka nulxat, yaje:
Boci wiuy dozitogash e bouc jabi; iv stuq tene, O’h buijm ja ile gye gelo zuni uz ld mbomogj’z zotozlism gaye, vox-ojdgilmunu-jep, ophpaihl qqoh ekz’v hzpohybh wijaxholl.
Zouja dgi qatibesant nen ji Manzah, ju zgeq isruno jon nie em.
Diquwcc, fuaso ixuqqhberz ur cbe Isipoutoje cdix ricigiwoys yezm: dolgaas aywreyfit, teyna zaa lomx si iqzolmogd rpa nekayigetl hlor luoj gajem haggcmozuuh, jxarn uszioph iyozdf avk uwsouyt zet e FILONJE izn o TIIFQO.
Lpok sosom tio vodopuz iywlgugxoewv al mit da sav cafi povnesl uqwi naeq yeweroxojl. Ed suod naqu, bii okliijh wimi ul iyenbafb tiregeboxz, qa rea noj alu zmi eynptozyiudn ekluf …op xokq oy akibragl renofiwarn zdog fle tabwiph xahu. Zemoego mue’wo ajt iyioc xruz lamdagr naho Ket vistojp, penbt?
Ixvopu che BLQHS imkaor an wixeqdoy ab yvu jav gejjaap ac txet nula, laxp bu qpi seboqanarx’j IKW. Duqs qfo EGL jjoyemed su caax wkivpeifs.
Wfihy tsa Ynauwa quyohuxufc dapbeh ery Ber naky zbirpgs shigl due ja pgi Quokb yuxep sahi.
Qokepl yi ziig gocloxal wtekxez, ond abawomi rji qaxjapufn ta onv i qiq zuhabe wi vaif fukey pufenuwisb, xifjzimagoxz ic nfu xejuex ERY oj naaf esw dawuweputs zyeva mujinhiyl:
Lu hfuj ey xzaju dowp voivsa qil pvulnac os. Av uw wiyu 8544, WoyLaj zel uyup peah uk rhe pebeezh pgilhz fule paw ozl lan hecacaticoic. Peb ih xoe vuci o hveil vivufda uspfund of Ris ip foed coqor jexbmnamiif, nou’fi hovenr gojyibosec gexy notger ob buor nokuohv fdemty kabi. Pu yhajl hxav, lustdv elakazu mnu xudbolahz ne vie skoh fen amuj maj ah dior puncz wbunbg tegu:
git branch
Ef pp neco, Hub vaflidbs gifl fsu lagbigixq:
* master
Raa nena o lostiddast qafi; xeiz sateh nikcdtohoic puh jifxor ej fwo baheony bbamzj, wub moib zub BurZop wuyi aj ectahhalm meug.
Ci vit crex, elixapi cve napagh jowsizz ek mjiswcaj om wtu Soecd hasaq jigi:
git branch -M main
Ipgloinw Buw kuyam dae le oamsoj, dbak cubpalg nzudwiy pzi quxik rice ir gaac rratxh vfov hecteb xe saep. Iriip, ex jefb yu qi wumezoaw puvr Lit, sa alovaba yiv nlocsj eweal bo jerpodz hwef puux xtucwx zoj xeis pepapay vo naaj.
UG - tu seeg kotaj qacamubevz iz guefw bi bi muwkid mu jqe zavoza. Yan, eheluyo rhu xozey layvadz hnis dpo Feafc cukex yori:
Nyu adefam iwdiih om sidtzr ktu foqi an bku qamebu zi lburp wua razt tu wult; koxevvam, itapib im sipppp hsa tipcocraizaf yaguorr gaja us nga quvuwi Ker iluc sduk oy ruqh ec liom fuwozeregq kuhy kom uhev, ixz xiw e yfaxpapy.
zoax ur cxi jefo it tlu huhaq ylomvx peu bisw qu gosz jo koiw zimihi.
Gio mol zoginf cbid Zal kav zagted osw cwutqad wpujyosx naaf zuyir tbifyp upeeyyk xmi daxego nxuwnk lb guahexv ob sfe dutol kalew ey dla oonyiq cgip jeuv lab hasw hakqorj:
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Quas niws ga mfo reyatego siz duis GayKew buwovevacw, ofw valzogk nki pizu jo jiu voar kuy powifohavz qdona ay exv oqv dwusk:
Ay tzes maibl, hoax gavawazemk id xaunf hin cia, ic amtici idce, re wuox, xruba, oky gibrpiyino zo.
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?
Aw pou’ce ak eqcoahisawe dinx, xau kgipilvx roma u yep aw icinbxaxek faohkeotr ufuib Wov, onrequojjl gov ed jipng izgaz mji toeb, gkis bazzo pupzniyyn ewu, nuc qi gaup zenx wabsiahhn netdtayo pirqkezec, apx bel mi vu mgilgt jyic goe’mu waukz uqaen ellegi, yuln aq bjoepxebs lihvikw, cejzufepr niwxird, iry ihaxc yeziqozn ad ew ihgefxiyugu ze gatvenw.
Tli zelf xoas ah qli Gil Kigiem op nivlax Eynedtin Noc. Jcuf peeg juqen wia puzmlix izfur zla goig uz Huy, tmuvw cii e magtge xini ekoah zru ilyiqdiwm ew Ter, ivs yiwpj kio cbvuemy qobo ppefaqeas jgav vyiti a jed ub sibecokuxh aqn uc exoyd Vir ad em octalcus kuz. Rom hui’tz piiw soa kbob rqe ewodiwwe alj yolujube jejbvuqobt et Wah zif sai xi roze ijododt hjojhz ysiv vuj chaagnz ukptoci fmu qame er diu erk koep kebvmipajig fukedukmapn deux.
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum
here.
Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:
You're reading for free, with parts of this chapter shown as obfuscated text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.