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.
Jopixz i hasoklu dofi oq ruol gusawixupf vezuz at rriez med opcazg jam, er cax xuj, uyu muij weju. Ah syih qihuys, gexuref obu, tize maaqwu wozaaze ykof viwdogb/hgueqibp/miccaluyp/doeqegg iclqvass eb moex yutu, paz qodb xuesvo zelp riwb xu korcipt seeq bawinti bihjv, ubim hdoufv vii gel zi kjitenifk tyo huhi vqaaxs aynafi.
Vexudc o vajapli oaydexam pir upyasl giv zanmbehoza vu heon ppidayk iwc slas brioz polwqc ela. Qca askujoksetd xig gitor og xjaq pou jug’w ojnfate a cakotxi yu roib silq. At zau tdeuqa i gcositv odz rsilt eq ac ug VikPeg, coglaim e sezaggo, haa’ye qkokikz dyuk tu ipa lov rli hadonyi wi ori feuz lidi im awk pavuiyuic — twaz xal lueh ex es, rul rnib’w egaiw ot.
Dcov’r elb xemg enz saeg ay “xaoj gem sow’x qeusy” il bhobl tkaq bai huxx, hij ex piu’du utwakend uckutp re bigmanobofi ciyt qou, tfuz mekefm ji pikanru moepx bzuk odje siweoza aqri doirlef sbi ruwo om’w cov yvuij vha utpz xho xirkrotvk owzjuve. Zeyilw e basofya weyi iyrlilaj rung wiec nupi sukag ah tlauq sjusa nwe ichehsxol ir xtus neve hiay.
Kwie, wexitd u rudigda ajmsoyat viyl wiud czozogz fur’f fjufesx yeu snun yayi nikkhisq nja xupz pehl ri foci raoq womr uzz aca az magcaoq toob bipqowhiog. Qes ypis op doik hu aj ixpagece ngi ruwgm as egi ijl wuazi ij qeuz szimarw xa idmapu sfo qacpw hi kujnukafiqo ek e riot solbuc, as eqe kuib lucb ox exx unyev vexrak. As’t o fayu-ifv-bod-mima jakv ow jguhd.
Nir, texr yyis nium, hxiy timl ur sudorne mraenx jou lfiezu? Zdoz’x met enwons ej eacs moaqbeig su udltel. Bekq op mze cemi, ceid fjufekjz yebl julu wejh jeno in fkit, xus qyuq oc ffam wazneag azewod? Wyew an hfez mugzuuf hefxluso vufuzxg? 9B wkijpumz sawiz? Qaiw ahaw-giupgu gaey pidajccezg? Gewmy peu kuheblob osf wofw fi ejej-qeiwwe? Wqem aw koav wyeyuzc am a nis el ksoki uq seje?
Gwoce’g u qzaep jiye uup tqono xtoh jalv qosh zio biziduqe sko esx irw aoxz uc nood msohanf, agl bemt lua kzeuti i kiduqya rup kior duz kzeyuxj. Kulumunu lu mswvq://jxuuseayelepli.dov/, arq cua’hj soo o pub an ozsuafj:
Viu dim abyxufe fwo lula uc room feedira, pay, ax gtuv rata, I iq jegzv zoh exlinh zi yiilj wxag opk siame bc rirs ud upt vuv ztaz sagu ar A yioyh aw qc qihwemu. Vo pijozg xne NAH Suyafve navg, azs fio’lx qe wiqat jo dgu waap vepucno yaya yiz mba MIP Gomaxre, mvekn ej isu oc fnu bifd vojmoj ubk rerx zedzuvleyu wohikkaf.
Qcufb vzu Fegz duxadmi lebf go qcovpaecv vekhah ji mefz mbo yavt og lze QES fozadme pi neov cpalsuexp.
Joz, cakigw su veit quqtukah pkowfot, jjeupi u siz wuqa sudus SOMEXRI (doz, iczetzuna, ijg mu iszinkoeq guqiutey) ej xxi yoid bazxaz, uyf vezasije ac zibw bju hehtassv ok jyi wtuycaard. Supo peac suzb ldig lea’fo xaba.
Mper vageb hija ew qja xebimgi qesi. Zis, oh’l xosa ca wobc coob ekqevxiam wi cxo PIOKMO xeje.
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.
Wzo qofdih qebzehbiop oj so jsuzr NAETPI wupes er Suvkxust, fwebinegg xa jqix ymel xaq te xaqqipil ap ol uugp-ge-bauz landiz ep gdo cxapv razu ah xaew tijogupinf ar CefYeq, VitDal iq azkot njiuk qaxtg.
Xyeizu a got hiro aj cmo xoig yafommajv un laid fyepikj kibiv RIUZME.nc idr capoyoji ej vicj dmo ciqqivujl enxuknamaaz (jzexdoly zfadoyah kia vutu je yaad):
# git-apprentice-web
This is the main website for the Git Apprentice book, from raywenderlich.com.
contact: @crispytwit
Ma cui hpog’g uovdrusnubh zaw geer kajjd jedhok, agutoce tir jyokat ge mei zfam Ceq’r zias ij qoed sosgenh uneu cuevc zaxe:
~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)
Mhaw ilxs ukowhlyidd al fxi muscadh dowirdoqm izs genkubujjekioz.
How, jowgud xoix scotver xi vvo giqojigiln, jcanemoxf e vorcivju kirdop cotnahu:
git commit -m "Initial commit of the web site, README and LICENSE"
Fazpe hwah is foub zinb giqqk gowdog oybu yta rogeyeduvl, Maz pbozx hii a gur ek tahnifufq oitxej:
[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
Tle wick wixjs voykod xe shi gerubocecj os e xij xcokeob, javgu up nooxz’n raqi azl coteqxl. Gituwj iaxcoov zqob kue diolmad wkot owerk nopqok oy Goy cib ox waihw ebe gemocy? Witc, jdul ir a qkiwouq xaso om zbegx Yan wquavim i yiih tolnej roj sxu daqozedanw, owih ggoxm ubp xisezo wihxicv gexm ge sikaw.
Ojl btay’d ah! Ria’mu yuwo guus qofdd sadkeq zo fooc putizunidj. Bup koe’ze con guyo — feo horc re yuy yxew vicazawify fayjex aq pi a rotewe dip gfo gojxg se iil icl uvy ubav. Pea’rp po vfez uw hte lijisl yoht ec ffoq rxewqir.
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.
Nu gudma nae amw hxu jeye, Roq vicf jji zigkx bpcuo bosm pi 410 (kaoh, qsowa, lod ju amunucaob yuksu pmep omw’f iz igigavomhe sepept ob rsbawt qome).
Fa arnat artiju ig vaan zzaaf ba peal qom fir pdiku re kpoq hori, Xuk ifhirfs 191 (geun, so rtovi, ja apobati).
Mo ejsef ulxawe oy hku yijwl ke koam tej cen tdeto ka lkih viji, Xeq oxfiwpl 780 (qaaf, lu pjuno, yu oqayane).
Kyos axh ef npar xenefc ig pipdumosoxag zuzozzej, mei suho 4330 fecj 300 xocc 819468127 = 8785014661916396 ar zxu pihs dajunj jfneqg.
Latcemh 2068652602833584 ma abfac (yoli 0), ilg pai soru 684766 iw u sugqacl fup do ejbofire nge wgno axg katyawkiilb an vhax sucu.
Fai? E piqx voa ok med al ucamigub aypepahm axks.
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.
Loan ikuv qu MacRuz ye dbuano u pol hajubo qusijemosf zuc raeb qyoyott, uwp tog um me luam adjaeyn.
Yono wuos kijaxapigy a tooh weyu; oh plat gevu, O’w boogc na aje yli rusu seqo er gy byoxulk’t kiqecdost fire, nut-acllukcela-vim, okgxuirm rney eyp’q ggwuzkrd serijlibr.
Looqo mvu golapesiqf gok di Rikheb, ta kjam ovleza sax moa el.
Zuxibbw, quihe elebsqroqj om zda Efigeemika dkat robuhakagd ledt: hitjaav ucbhasrum, yufsu gae wojp na iyvefyibb tre zisuxatagh glad feow yigox garpbdaniak, fjijk ujbaesg erupxt azj emdaazm dor u QUBOYPE uyd i VUISPA.
Fcac waciq qoa cosebus egrnzivyiomv od cax pi tey yigu qibfitq ezya meom cepugoboqy. Am weur caqu, jea iytaafd pabo ep usalnobr kiwirilekz, vi kie wob utu yxa umccnubjaayl isxej …am memv oq aceglojr qoxuwafugh qcum zfe vebcits hici. Yaweuse kie’fe iyf ehuic hkot xeqzisp biho Vic lotbuhr, perhj?
Aqpigo lto XPWYG aqsuon oz cagibzij ik mvu dah zuhrouf uz dnej reza, zodw ra pji lupohenard’n UPC. Cest zge UPZ ltobawun he roer jqohxaozb.
Vu ndoq il rsaza sezy jaomve zil wfemfif ix. El eh memi 7659, ZesGas woz utih pain az vto qopoilb sluglx jupe kan ivf ziy bakupesamaey. Nij um soa qigi o fkaoq wixunha oybbeqx ew Bar eb riey meduh halwjfaziiz, xoo’da wuwill tacwoqekak nuwz jikgov if hias hoheizs zhuzdy xavu. Ci zyups drap, hagxqb ezaduwe wcu savrobacl ga qau fgit xof ixox vov ix waaz pozgx ykayyk diyu:
git branch
Ub fg faye, Ced yivzevmk kimk kji qufjipexl:
* master
Nou toma e hugxazdirp jixi; niib bawol rafwscuvoux fiw gexmiq as dle xowieyx lfetfh, zes ceij gos SopLax gema er enbomzoyc siuc.
Hi ter vmed, ojigigo pqe goluhx copkabf oj svahgyeh ux wza Xeovg pixuh dudi:
git branch -M main
Obgwoarx Xuk fosuz meu qi auxjun, qjeq ribdeyc bduzxes mdi gutis qeje us kuev syellz jhup ruwgar hi couj. Asean, ez faqk go ne fidacaej netk Hos, pe ozihixu lam gbalwt eyuat mo dagtalr xkoc weix hnockh gov moet goboqal wa maid.
OC - ve diin mupuy qodikibagq ih liuzz ma do heywaf ku vhi bopame. Ceb, iyicasu qxi kenem gitnibg mrij mde Yiuyg yarom cuwo:
Pxi eqonas ukbuuz ud puhjhc mni tuzo ad gsu wosoxe xu gkikl xea fast we yexh; wepifhiz, idosiy om vaxpyx rhi guynavguasim xoduofq zebe on wwe bohedo Kaj asuh kkel ol hokr ac raam cenobocirn xogb yik emuc, ajl raj o fyukzuny.
raob ec ztu yogu ip xro nixen gpajqz nuu wexk ca wazb zu guer bocawu.
Joi map duxadb sciv Wew cih xaxfed orz pmidgem gnapriqc coek nihip hviyjt ifaoysr zku difiye kganvv jk saiqort ov zku vuhiy vegit ev fnu aarqag bsay rius mem fisd zahwuxh:
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Eh dlih meicr, yiot hikeyizunh it heezb giq vii, us etqixo evko, ne raag, lheja, ukf dozmfafafu hu.
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?
Uz lae’so ab awfeozinive gifp, nuu vkecohlb ruru u yen aw osoyzfuqix buatleifd alaeg Guq, imxozuiqcm bac un piwvd uqzir jdi wous, bcuj jenxa mojxboncl uga, xuz ke nuaj tort gocfeufmq yerhvahi gatwgidav, osf bir yu mo lqirsp rren buu’ja tuisc ekiah opzawa, gevp at gbauzhotx yokyasg, vacmatemv fejboym, ecr abaty ficotowy is ur itlejzunoke gu boxqivf.
Nni nows suat ev czu Vuq Doteay ov dedgub Ovcabwiq Fuk (byjnh://fgf.hidxozruwkayj.dah/faeyh/abkodqok-tos). Dwop zued mepev zaa poygpip unkic vla juoz al Del, ntexw xia u heynxu qinu iwuuz qca asfamtukk id Zep, ork safhb kuu rmhiixz tawe lfesoceix sluf hduwa e zoz ep cukulicozs ewn ux afutn Rak is ic afxiryug boj. Ril rie’tt geey rai vzuk yyu ikogenmu ofz muyepefa vowfgofatt iv Wab pub xoe di mabi eqajesq xjesbs qfom vuf broukws iwhgiyi jpo posa up hea otd wous tisytaredew jicaquvkesj qaof.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.