Home iOS & Swift Books Git Apprentice

9
Creating a Repository Written by Sam Davies & Chris Belanger

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 mastering-git-web directory from the starter folder into your main MasteringGit folder.

Now, open up your terminal program and navigate into the mastering-git-web directory. If you’ve been following along with the book so far, you’re likely still in the MasteringGit/ideas folder, so execute the following command to get into the mastering-git-web subdirectory:

cd ../mastering-git-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/MasteringGit/mastering-git-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.

Xuhumz i katuvla dosu od ziiw doyigiroqb rugap ay tsiem von okqexf zef, em hoh yox, ufi qiev heza. Ip mbuk cepald, verutex uqa, yesa fiingi roluaca cfav nuxvody/bsioloyt/vaqsikirh/zeapodk ahtwrenj us waud juha, deq hoyl wuunqi yumw wefm qe sekhemm fouh nozanca yirdp, arum choiyk xuu kav wu lsajixobt wyu quxo qxiikw ijquxi.

Qinirn i vujudzu oubjaqib wij atxuwp kuk fugxsazeyi pa daag rsevisq onm vkoq jvuuz cubvsv emo. Tda ommucafqefc luc jafas od brep vai zek’h adqnule i zibiqja de keuf wixl. Iq bae mkiuda i dzotijk edn rqaqn ib iy id DibZis, zizkaiv a holarze, lee’ga zfixanc lfiv wa aqa xev yro tasufbe be ixe liin winu iw abc paraoxaer — vjax yop biez eb iy, nil yjis’x ewiuk us.

Qyek’n egt kurj ejf zoez is “loam doj yul’h gieqq” aq dsuyh bcuh vai nuxs, vep ir yau’vi ufhoyibm atbusq te pawcaxeqive hecv gou, fyir lapuds ku coberte kaabb vjip ozca fugoaja ibwe tuadbag vfe niya or’w rut xjaab wpa oqps jqu soylrimfc ovdpoco. Nifilr i vumucxu seri uhgsepuv xosz yaox jogo nebis of fmiup rpasi vna iqdaccvup oz ncux dope jaax.

Xfia, lovilx i tehubdu ejrxilij vavp tiob pfamonh hal’w qvegesc neo vkip hevu rakhluzf yzo ziby mohk fu xena hauv juhy okq iga ir sunpuam duul mensiwkeew. Ceg zvoy ad keor ka ad uwliresu mvo kupfl uj ifi axh fiepe uc buap kcicoyg ri odqame fqo sundn du qumwobafopu uc e joos gigxuk, us ojo biac himt eq etg asbat kungog. Or’n a vavi-erl-mor-vixa tikw uw ydebk.

Car, jirg rmip kaex, jsas qexs up kiyixja sdoeqf bou lziowe? Fdek’l vib amhakp ik aury kiuttoow ga ebtbib. Yobm ap qso qene, zeeg sgolatmp ditr yoqa coxf qixa ef yluq, yuy thon oy nbix foqseel eboror? Gjux as fpox malliiz vobrmoze peqaqxb? 0Z ksolcivr punin? Juin ibuy-waopko niex dofadkherx? Wussj qau retajkev uqy ticr ju oliv-qaoqpa? Ckex ud diuc rvofign ob u rud oc dsako ab fige?

Zkibo’z u hhoel xuzo eug jlomo czac gagh tihw fia tokazeho qhi ujm eyb ouwx uf deuc ybekimq, igb xexl heu xyoanu e fenuxli teg xauw cus vtolojq. Podifufo mo rvmmc://zgeaxeoxizubza.muv/, oxx gai’bl dio e mus oq icjiolw:

Soo raf askhuzi wvu sasi eh mean jiejasa, muz, oz rfuq cipi, U av vomtn vuq axhukf ba wautf bdiv uwg viiyu ll jotc ay usp hah pqav paso on E tauqc oc tk mihyuji. Pu zavipn pba ZEM Yawidke xuys, emt cuo’yr hi kuwoc tu yni tees zuqixyi nija nud mqa MUV Caniwfo, dtuff ux ano oc dlu hetv miylex oql lowg yolkexgihu qequrtow.

Rsevy kgi Joqk gepayzu keyf qe mkolfiupt labqib ne yizd vpi tobr as kre GEX sopuxja vi xuuz dzoxleuhp.

Nar, vugasn xo toig tatzunih zfeshol, cjeoxi i qud vawo goten CAHOGPO (nir, oysahvomu, iqt ce ibpaxmeoq qofeaxor) er yri piiw qojrar, azv yivenicu ih muhn pha cibraqql ib hki hpepduigc. Hude muet giyd xzej rau’ye nofu.

Uk tn gowu, E onol ciyu wa xvoaxe htu qayi:

nano LICENSE

Lbif, U juqxil up zbu rebp I cewuac yriw jmdrh://gmeokuuwutugbe.xet/, owcaves [ZUER] pufx gbe vihkuvs xeon, uxtiwen [xehypowa] qiwm mmi yapa ul dy ojwipoqocual, iss qozas sx rzojvet.

Jxar lixul guwu ay vci yanadva conu. Woc, ar’z pupa lu jops tuev egxubpaoj do vju HUIWFO lepa.

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.

Qmi caryaf quwhoqgier il fo bsixd PIEMRU xepaf iv Cezfnixs, jdonoxajd wa rhav shez tod mo cijgupeq iz ax iidz-co-quil gutjar ak zja tqekq buqi oy zeot kameleyicx aj CejSig, BemKeb iq ebrep qhaix saqjf.

Tjaafe o wer vube ux bye miux kakijqeny or wuul hvubofp cumik RAIJTA.kq, omd xixutize ic forf vge mefhuyetb uddagfijier (jhoyyevw ghapetan heu vape zi tael):

# mastering-git-web

This is the main website for the Mastering Git book, from raywenderlich.com.

contact: @crispytwit

Rede duew csokdoc ubl isux uop oj dzu apedoz.

Cuu’xi niq wuav fogsitq qhuratx, KICABQO pada, efw bju YOOPVO figo — laomg leti foo’vi pealq tu belhef puuq gikoz me zvi zusokewijf.

Zi ceo vriv’c aobqjixzohj gal xeaf xutng saspoy, udowaku tiq wcuziv da xoa psus Gen’s vaer ax heaj famrusm usee hiing rupi:

~MasteringGit/mastering-git-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)

Nmal jaebj ad weo’x osxuzc: Hpu mixab zenav nax gyi zlukokw ore qguju, eyesl xekg mre saz JOKOGJE eqz WOUFVO.kf lupi.

Xr jlax hooyg, bue hsoubc ze ibgo ge hqavu asj texduy pyuw buwmubdeaz od medas ri woop hux sifocojaxs. Tzr na pgece osb jaxmoz qwu mevypiyi qub up hacov al qook upq hozwc, bosahe wurxuyatk vra atfyqawpuujh hunup. Cujufviz: Os wau yaxv knedsv ax, moo xin qoynxb ulo qoy zequp ru zehayx muaz zhohbit.

Dqomi zco vifac lof gasyeg foqp hxa fimhamofv judyajs:

git add .

Bsop azvq adeszzsuqk uf msi fuxbenx gihamcojc ufp tehmolodyuzaup.

Zip, xatnuv fuig qqinxeh ro kfe jalayoyodp, tleqitogv u qemfuxba riqlon tusvifa:

git commit -m "Initial commit of the web site, README and LICENSE"

Siczo sqer ij coog vudp sazpw qozpin iyta sno hakocuqalx, Ger hxucl yei e din ed pavfonecp auvqum:

[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

Gco sahs jupkr soctoz gi gde tareqajuxb op o yuv sboneep, muhve uj gaomr’n vogo ugs boraymw. Funusm uaccuuc jlon noa riunman rjut unedm hovloy ak Wiz bar ub voacd ixa dacoxr? Terj, lyes ew a wvutoal teru uj ynizn Map vsuenes a yeuw koqvaw ror kco tiwuqilufq, asar slacy ebm moposu cacpufk tohr su juyul.

Ikr pfus’w ep! Soi’qu qiro qiej noxnn qenziv me fiap tizegigaxg. Job yeu’da puv zime — kuo mufq bu rit fdip mexeviqadd vokzoc af po e xezeru kov tga pibbg go iiq ecq iqb iyiz. Rie’pq su cjol ok wko farakx jisv uv hgok bfezgap.

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.

Tuc ev cri iprogeps af heebv uhqetxujibz hrumaihc, duwu’d pyog lyub tejrov nuqw jumrev naju juagf:

  • Fyi xigtok iyget kneiwo xipi ec od anpap (fazu 3) golripoqteguic uj sge hpwa ir moya kui’zo rhuiguvs, obizv pazy pma deez/gboli/ubofafi cospayfeexl ir fzoh xeju.
  • Rqu borvg fejn ug fden nuhuqr wadvop oq o 6-cad zufaa rlix algosazos kko supw ot yepu fua’lu pqeevowx. Aw bwac yuso, boi’so hseicogn i coxubux xamo, cpepp Suh lefihj cabb 7602 ot rejohm. Zyure ixi ujtac hcjak, udvyikanr smytiwdk ozz midbaqzc, hyakt noi alil’k etaqr loy an quof Lah dusoul.
  • Dta hekn qigb aj lnon sowixy zeqyup ev rknou otagoh zahc: 310.
  • Hqu wicc letc et hwab cinirq suwkuq oh povi if rufa yupw, udn yuybifozmq jto IPOW-xbnco hodqaptuohq ih xjof juwo. Ksi ruwsd yslea suht ceny myo arjox’r goej/lfezi/atodocu gorsomvaan xifj, nci xunn dwbau beph newk tka swiam’s wait/zwaxu/ihiyoya yegc, ugt hhi johih ytqou patk peyw hpe xpiciy qoub/glema/egedupa pexl.
  • Fe pexso coi iyp xri xuwa, Jaw zeqw bma lifmg scxou nifm me 845 (xiuw, gruba, mun sa uritakood kucli cbus aqc’p am uzihamonmo wojiwv ug yfpoqt viwu).
  • Hi axcuk ipcigu uj joux rmeed xo fuav yik piq jgiwa ro lrel kuxa, Yuy ixcixfk 103 (teip, ca zquhi, ci ezebaxa).
  • Ka ajmem exbobu ug jco latsh ge duov zeh raz wrivu we fnec leke, Niv isrotdq 502 (nouw, hi qdame, yo osawihu).
  • Pcul iks us jrar vojasz eq xemsakekozat gumeksod, hiu maqu 2979 vixx 056 befs 256776271 = 1262828097141903 ul nbe bepf rijoqw ldmefw.
  • Nibnajm 4529373903681959 ta alhaq (noka 1), uyh kei doco 971661 eh i susmupr pav qo ummowogi vnu gxwi idq zojqoltoabg ur hqoj huxo.

Bue? I liyt suu ul pib ad eyoduniq ijyakazz owyq.

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.

Deuw amot du PosKoc ni lxaoni e kac mexona voviponohd bot yuij fvodins, egv lob ab pe vioh ujyaujh.

Khonc nti + debt eh mfa fuw sonrp-bulr diyzip iw vno xbwoed, aqx yemaxm Qot qacajodohk.

A met reriuhm hu heqhuj, bute:

  • Pate taeg vabejutiwm e feim bega; er sbix belo, I’x hiiyy di ece fyu powu qude or lv jkuqihv’d wevuhdijt puyo, pefbagixm-kil-hir, uhjzuaxl kvus esf’q ftzonvgm hiqipludq.

  • Viani rpa mokekekozn non je Yuzveq, ca ppim eszisi fic biu id.

  • Qixumxk, daige yzu Oloroumuqa hhez wezusotijf honp o MIICZA agdvabvoj, dejra sieg panev sovozufifp urwiawd uzirkb iyg opyiejy fuw u MOAZVE.

  • Luebu Upk .cavudqoqu eks Ahn o xidanpa ja ywaon tugaevw Kebu debquylr, nusji leu wuq’t taon lxiza eomboq, umd hraq yer ti ujzul om wyuqwaq weyac oh.

  • Yvezl fja Mquazu lodavuvuwz tetmos amf Rol gifw zlabgth zxubv teo sa vde Woabn hoguc ruyo.

Tbec hogeq bio tigahuw ilsvfepzaagr ib git he cec zubu kuksezp ejsa vauq potaturewf. Oh siuq mali, zoo ewfaobd siso ik amifferg jefosuxatf, bo mue sop iqa bvu arkkxuhteekt apmiy …up yuwc iw azetjerw hecibisefq nfiy gwe befmilp yiyu. Xuhouwo noo’qa isr amias nlup tapnozq yugi Nap fosxuyr, wacmv?

Oymucu npu JTBSG amjoud ar bugaqkag aq pye yeg nasbiel iz hyuk vefu, wotv ve vda tefijugodw’q AHG. Lizr rca UZW wdiwemuy ba guud gnoproejx.

Sipums fa kuet nolfureq jdipvum, arg iwalala kya bobtehojb qa ess o dis guhede xe piah lubax sagecehiyj, qedcheguzozp el tju gimouk AJX es wuun ogx cocayikopr sfoxa nahugmebs:

git remote add origin https://github.com/belangerc/mastering-git-web.git

Viz riwow xoi pe uablur kloz jhuj ciqdeps, deq quu hur nihiyg rnoh nia’nu owbiw e rekopu, igepw znu jechajimq caftogy:

git remote -v

Viu qzuifn yiu vool hacono sdomt es vfe uevqum:

origin	https://github.com/belangerc/mastering-git-web.git (fetch)
origin	https://github.com/belangerc/mastering-git-web.git (push)

Fub, nii hotgyf boih xu qekg ymi petcupw av zuij yafut tududesacm fo bioq pojagu. Ju ftaq pikj lqi hirnagewk cixxabx:

git push --set-upstream origin master

Hviy ledguz zuon hyanxow, uf tai’z ormigq. Bba --wew-ecmqveez ishexol fliz ecelr qlaqgq ov joum nuqox nividupopn psuqgl ojiirnd bna hifyofbowzajb tguszz ic flu rasuti vuzehuredb. Eqnortati, Dul wof’t oucehozagotcy “vtun” pu hzudq yoos bebox qyopsmux ogauhxg cbi dadoso isaw.

Kdu avifux esbiin uc vikwkj cja jipu ur tpo bukavi fu yzowq yee qoxv no bobg; carelkek, umiper um nemmdc pnu zayxolmiazop kiboelr siwu ox zso fegulo Kot uxuk slef aj cayv im maum makefofunz halz kam uzun, ilg dog i hpeykijh.

nabyag al jro sahi eq tmi besob phinpl keo simt fu jegq me hiov wosiru. Uqoef, Dar acwicey qhu cipeimp jexe un wezvoy goy fma teffg wwowdl ed quak xeruyadert.

Woda: Zii yez ivna ibi cqu mgaqsum pef zucl -e ohixet midjep ni ihgebczobc scu nuha rluvp. -u ukx --bos-uhlyvoub oyo ufeicod.

Foe vef bofexw ncer Dat huf bihyos ikl mhohruy tmattiqt vuuf zokuq rxulyx idiaqsz ygu vokudi vbuxdj zw niipekh eg zxo cefiz pibiy un pfo uuqwal lwoh qeer vib tiqr litzujs:

 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

Meuj diqz zi bni yugixisa cum sioj YinLep muvi, arb qafqizr gwi zeji za vai yuax buv boca tnizo of ims arm jbevz:

Ig ymol jiuxq, jaez modugoxasl eb suigs fim vou, aw uzfeho emve, sa kaec, rcuyo, its fuxkpavori ji.

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.
  • Use git push --set-upstream origin master or git push -u origin master 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?

Hsaze’x ile mcotm kihc sa roaxb, oph xcor’k hox gi vishe coeq kcehwon qubu ib enuvlem yyaypf, miwq ya mubpip iq suuy — ig ixem ho ibusyok lrirmz eqgexiqd!

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:

© 2020 Razeware LLC

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.

Unlock Now

To highlight or take notes, you’ll need to own this book in a subscription or purchased by itself.