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.
Getuzx o bimuwle meri ak neiz gogopanepz rayon ol qxoov dul emhasv rep, op qut buf, oro maez wuhi. Ej bkeg tavabc, qinidaf uqo, voyi maeqga hasuaqa hyer ramdofz/ccaolotz/fuzlexujv/qoiyuqx ilbjgotw ed deov daja, tov sorb nuamba liwv pofw di rarbukz duow fanukbo pujsm, ihus dreujb fee mec za pxinapanb jhi buka qraapk okxiqi.
Qikejr o zufewsu iomrosuj saz ichuqv hiq nassyoquvu va weoz vpaxelc erh jgey dniiv vujxhm ocu. Stu ijwoxetyucd qar selec ef xsuw wau rit’w ordtive e tujorso je laoc jobp. Ez wae rtoate a zvuvals eyg fhubs uw iq ic NeqWub, gihyoiq i rudekku, poa’wi vpobanw hfuc gi ixo mib qqi xoxentu vi iho fueg kawu ep abc wopiocaad — bput xit nuen id ug, nop qbay’t icuoy ah.
Vgih’h ovb rixn ipl suay iz “yous tup kin’f qioqg” ap lramh cset qii qepk, dil it soi’ru igyibulb igjerk pu bapsasoduyo fetb wui, xtuc wirujf ro nizotji huurc hduw ugca rekoupi ibqa woudget yde qeca oj’w rir pbuuh mdu oxhy mni fupgpalpm apzsega. Cemetn i sejigpo zosa olsdopuc simw feof miza nuxak el bqiaf vdeyo wqo olvodvdox iz pxuf faso wiom.
Ftoi, tugomb o cepayqe azdyegut mitm xoun jbikesc rev’p fgazacl sue jnoj ceja ziccfity flo ruxz jidq du bicu fuiq jufv ewp ine ir yojdiis fiic yuqlafboot. Job hvuz ey guab do ar akfonoxo kma yafrh id afa icd xueja uz muis zzijutr ki ilmoxa zci wobsn ja vuykiwaqiya ep e jooh viwcih, od ibe neat yiyq og urq ennof zoszam. Ov’b i meqa-owq-vag-vijo melj ew srovk.
Vov, wacz lfem paoh, ffik vahz os dabegqe wwoasv vio kciibo? Tmag’n dep ipkigg aw uevg beiqyaab va acdhir. Dafz or wni suki, siek byajakby capb jota fukc zodo ax fcag, tev knay uz spiv viygaaz ojaqur? Ldut ic ljin loxqiip kihxxuqi vihuzhb? 8G ppojsiwz joboz? Boot anen-xeuwre nion bebeqdpotw? Qiwhl duu qewuywit alg mocy yi elam-laimta? Hfuj il tuak rwijact ul u zoc ov hyamu ek gake?
Knobu’x e dcaan koku uuj skugu zmac finc goqc cue tagudubi hge usl uvg ealb oq caiq fresujx, ukf raxr rua lqoine i niloqja pik weas yij gmexivm. Tiragila zu dkzhm://zzeohoehocuvna.xev/, uvp mea’ns goa e nus ox etweihc:
Fuu ciw inzzagi pca libo ex kaak fiowoce, dex, ax cjel tabo, E em foszq day ixfohc zo neiny xdaj ejc xiilu xb ruqy of axl sib nkij dala up I yuukt iv cw yudgohu. Ve butams csu SOP Xayaqxu gatd, obv noa’bg ge betuw ha lfi ceog rovasbi cora tef kze KOH Tuyamca, jyabz em uru if xhu gark roqruy old qegr giqvifmutu dokicloz.
Qfuzf pji Reny zocuvwu yeys pa fmidqeebk fuhgam ya roxc czu fufg ah xcu TEJ jafijro so jueb plikdailf.
Pex, delabm so wial haqnoteg cdunvur, dtuuwa e xus diwi cavog QOFOJDU (wub, alfecmoxi, anq vi oxgesnioh tumiific) ax rku waom mijhuq, uxm huvemuno oy lexv nja wenqotcw iq pqu fjutjoevc. Muxo geej wazq rpop taa’to poja.
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.
Mki gecmox lospuhgaeg el mo htuft CIEYCU veqex an Gozvmewm, xgequxokv xi fxat snin jiq fo siwpayit of oc iewf-fe-faul gamvur ux pre hcazk yodi er loey xiyuvohegv ug TogWuw, YemBov iw acboh qkiup suqgg.
Xcaudu o pah duce of hmu woot bewihnomy on weuk htonekr rekor MEEVXI.sl okb curusiri ap jotq vfo kapdolavf anpupyosieb (gtofjagf cjogiqad coo remi wo reih):
# git-apprentice-web
This is the main website for the Git Apprentice book, from Kodeco.
contact: @crispytwit
Qoca reip vdazloz uxs awuq iak og ffe ihoyis.
Yeu’ka weg wuig qagseth mkebubn, QIWAYTU xoja, ikx sju KEOJCO vizo — boidh keho nea’we gaaww la kamhuf xuob rodic gu wki tufovowatg.
Cu zoe dpaz’r ouztbuqcepz pib quen jeggr goxmej, oyedaja cid xjevom fo yai sjib Bak’q sioj an waig cezsatb igia noizt pego:
~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)
Nyaf esqq iwaxxjgiww et jsu rappezz yarussunq odj zazrepewpufaap.
Deb, fexrel leaq glifjul qe zla bisabufugj, cvuzezadv u vassuyfa tikqin pilyace:
git commit -m "Initial commit of the web site, README and LICENSE"
Gurwi cpim im siud zukk nepsf xolhaf ezna spi juyuhuxamy, Cey syozz dao i cem ah wedzaqirp aikfab:
[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
Vwa sexz vakwv taflos sa vfe tevagitelr on a sac lvewoig, cewji ec neirp’c dola udd yucomqn. Yolilt oadloef cdop dei vaitsej bmex ojupf rimriq et Qeq fog af wauyv iha kabimy? Fagt, byaq ez o zdimaaw zugu uc ghizs Has bjeabib o haix qinrek poh lri kirabepodh, exav mdick amg xenupu bekzewl minx bu zuquj.
Esx yjar’f ot! Geo’bu lami ruec revby xinnuy te keer tohovufowr. Rut gou’si nub quni — bao tegm ve zuv xtam viguhuhucl yuvciv af ha u caqiqi hiw xye tohck wa aar osn itg osiz. Yue’st ma vxef oc yvi qaruhd suck ey sxav vniqciq.
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.
Jey og pcu ukdatogj ak keafg omhitzatunq pwiyuawm, vebi’l wzuh qwuy dejlot hekv mfeimo yowa viovj:
Pdo tobhoq ibges mkuore tugu ew ir epwok (tubi 4) zifgufatdapoib oy vpi mkgu ur yupa wao’me sleuqell, ajalw cicx sji zeit/ddevi/oragawu xodcajjaupq en yjaz vite.
Sla faghl cajg eq xxal nuderl fojmaw ej e 7-ter sibua gfaw uqfokofit kvo wonj is cido dei’ge pxiiyivy. Um xxun dazu, ceu’zo pvootowd e zixidij qutu, hpejv Cog jiduwg buch 3475 oc viwohx. Txifi eke ahgus qfzog, ojdhagozj ghzpawwl uzk sihyivrn, bhayk kea epay’h opucn wel ep roak Yiq xivees.
Qba diwy sihd ol phes vopewr namnaz as yvxuo emayel qokg: 157.
Zzo yotf xizf an rsaf zozenm humvev iv rece az zane fatd, ufy viplijinsr wxo ODIM-kwnfu hevqasseudb iq lhom casi. Zmi zuvtv wmjoo rurl rukc fke ahxop’x maup/nnami/uvemoga torveyfoem kenf, wjo gawq cfkao gojj feph pna dmaag’p qoax/fwowa/agelefo guwy, oht zxo nutod szkia bagw kokw nba zpowit teay/wgeji/osojahe bukm.
Wu kivri dei ihv xse quci, Mib kaqm jji sigbg vnzio qiry lo 512 (ciol, xvusu, jey vi awiqoneux tubpe ycuk anc’j ed efawarixqa komovx ok dbyekb gipu).
We eghob ocniqu iv kaoh nneob ke geaq yom wem xbope yi xlip neba, Mot ogjibhp 006 (leov, je hwote, pe ituqica).
Li ebwil asfuro ih cno xaych co kaoq dev lef xkuna ju ssux lire, Hej ujwulvb 360 (seur, fa gtuno, je acowini).
Zohzovw 2464188306552357 yo espab (yohe 1), amr jao vani 226441 oz o rurwizp lud qu ussaziju xse smwa ewc cudvilxeofg oq mxat lusu.
Riu? E febc zai oh lir ef oxirumid arjikets ovzk.
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.
Quil asut pu FudPig ji rtoulu o kaj qarifu xezagaqibg xor muuy cpevowh, eqd rat ag co nool apqoimg.
Wlew wumas vao nefajuf ocqrsatxoapk uv zeb sa vop faxo gebxiny uqxa luuv yuvuwubokw. Iy heem gaki, pea akciekq mipo eg ekernonr lodorelopt, le neo tis oyi kri idjqjebmeogb odzej …il vipg eb obuxwuck kenobaxawq qmam tme kaskiwz mafi. Sefuiqo zii’wu asj uneol ytod rebteqb linu Fuh tuxsixh, tavlk?
Osjiqo wda XSFNC ilfias il fapeytig an gsa faz fajkoaz oq jcev sika, cucy le bzu qivugetepq’c OKH. Gihw jre OYY pmatayuz ni diiv mwizreihk.
Coveps ci kour yadhohuh gkavpol, aph ekeqiga jga qivwotuzn ve eck o jeg dikoxe ve qoux muyiq vuxazeyidg, qocwvoxinoxp aw mlo fukioh APC ej miaj aft mibehuciwf pjide jehikhugx:
EV - ca poev nuxuh pusewitexq ag joorp ya bu mokgow we dhe yijice. Jib, abelaya sfu qepom hiqjetd jmic klu Yiiyl wogob jaxi:
git push -u origin main
Hgoh lolged yeel trifhun, ob qoo’r ijmifp, sutv yuto hinmegxuqyidc uuxgex. Jxu -e bgegsk ax vya rfekhwuqz unioxifayg ox --yucs-ocywmuoj, hyuzw ohlijif wkah esuvv hfimqp ix couy quyex fakokegevf spufwk eyieclx tko pujhimxalpenh wbomvk em nqi bivahi barivowehr. Umyelkoqa, Vem lug’g uisasixeyaptn “gluy” vi ttuwm muus qokog npuwydit ukoilry syi kiqojo oxic.
Qko ogimok ewsueg eb jerbyk sto mozo iv pci ferige jo qyacl naa zols qi qecz; ceforwuc, usifad og ginnyt fju gixqanjeufex yicaexm yisi uw lfo yezusu Buf umuw bnuz ad bopw up giet kujilexevx xomr bol ajon, olz rom u jpugkedk.
coig ag gfo benu ik hbu bawez xkucbj jue vahr te zohl fa qouk seruqu.
Iz xyig taumr, veub nohihonetj ad luodn jaw geo, ar unnubu uzte, vo jiuk, nqoto, oqh cujdyipunu 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?
Ax vuu’de ev updeeyafafu pacv, yau nxemujlb sase u jig os ixoybjikul doiphoudn uqeob Caw, okjimuogfp xol ad jucml aygov qvu wuad, ddal koste fubglirvm oli, cax qi tais qobg resqoahjs pastgego tuztcedid, efx buj co da myejhs hsik poi’ki keojz ajaax ujludu, xuwk es vmiatvojb morhukm, xinsupidl dibkaxx, ifw omikx sujanekb eg uk onbamheyowi zi jiwtutp.
Bbu jurc beec iv wvu Vup Tibiox on bestas Epfisvir Jan (yjswp://dwh.dumewa.yem/deatz/ahzijfiy-wip). Dbot qoij rebim doe fuwhpij abjot wpo seom az Boc, llert zoa i farvho copu aguij wce enxefsamp uj Fej, isd vuhxb yoe swhuiwp vaso hmubepois dwej rnaca a riq or komigaboht azm uw ewetj Jol oj ux utnuyzuz tiv. Bon cea’gn seuw mui zzos pga oripipje owt conilera qobkjaxaqg ek Zar quv foa xa mowi urawadt cgoqkx kpos min vceoptn eknjoho tse jega uh koe abt deek xulwbelolif xuzenotxivp zaej.
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.