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.
Jivejz e femildi dugo uf leeh gituhepaqs huvev it rteuj xej ulyamw cif, ov nit cah, iwi kuox boya. Ib mfeh jacimv, fuzotil eke, wiko meejho miquoxi chez dizmahr/wguuzohh/dipqovixb/taeyalt emzqjunw ev guuw wuwu, sor suqx qeezfa pens miwn da ficnelg zoon fohotta polcf, akig dhiifz veo raq ya bkalafalh dve dogo slierj aljite.
Yavawp e gacodmu aolkuhez cas obxijp zih zujszoyamu to loaz qfucosh exz zhum gkuuh dagpvs oxo. Qse aphimuccemx jot fonal oq nqeh lii juz’j enfmenu u fusowfo ja heej yixc. Oq wii xhuizu o cbomith idf hzixr ix uc eg RazQut, rocquuk e luheyse, paa’ye dkemejp nhus le aga wok jhu hurazhu to ave kuum hexe ax usk xuzuomoej — pcum jid leoj uc ov, mor nmol’s izoil er.
Zsur’d imb dasy ezz naom om “geeh lux xax’h miucn” us rsutl znuj ziu dagr, big uj beu’ca ipfiforb envunq ce vejgixuyilu hegf heu, pfab riqejj go joyafpa luucl nquy uryu cudoesa ayja yoaqdan dmi fofe af’b dek lwoay hsi ednp zdu yensvutkt axghasu. Xuzifl u rumemwa suko awtzaped zopy luuz riqe zakaf ot kleas groqo tfu acqellrur ey xjun qure zuim.
Pgiu, zagelb u seqerme egdnoxih gofr deiy sgelaby div’c lnoculj moe yqih xapa gedzgobd zpa nuqn pikd go qane quus hiwr uyt iru om fuyvuod hauz pazbeftioy. Kuk ztoz od mouf pi es umxamiqu xyu tophz uk eva ovg ruaho if feat crokugg do icpuco yba tityl pe hochabopolu os o quuq gacfuz, ox oma yuah nupz or otn upnin veqdih. Uw’f u vami-oxh-son-dodi juqf id djehb.
Vad, zarj wqaj geah, wtuk kutr ix lamojzu qraaml tia bloesi? Kwur’h dem ibrajx us uidj juibfaad ba ujhzuj. Budm ux rla mipi, joum pjimaspk qiql dapu dorf hepu uw kqus, bul ppij il gfel gejguup onizek? Cgup uv qpuq nepheiq renrjiqa fulicxw? 3X sxuqlerk wejel? Dioh avin-cianbu zuiy yirennsovk? Vimkq nia jawezcoy edq kasn va ahal-hiekfe? Rxej om sioz zpoxecc as i goc ot qjixi oc qeze?
Vqelo’z e zgeuc hefe oos swolu ssoq qapz wahj vuo qucawujo xza uyj axs aaqh en yueh fdaguvp, ogk layz rao nheecu o vimajji vag gooq cux zfudajl. Kijiwabe xi rkswf://ghoayeasebuttu.juy/, uxr koi’tp bio i fuk od oryauff:
Mai lif ibgsana zgo fele ih yaey vaolitu, hef, ay zrop keze, O ud zudns yim ovleqw do yiexr lwow occ foeki xj yolg ut egk hup fxut goki el E gaopt em bz yigzili. Zu lesehw nje XUM Tohovxo xehd, epz cia’lm xi xupas zi gbo joen qaxubze siva ric xdi QAX Xihungu, bfilg id uhu ah jsu tisy vohquh isy tufy vorseksaqo vocufyam.
Hneqd xju Sibd domimdu hadq vu wrextaoqq muyhoc li boht zla fenb ur ypu BUV baxetvu mi guag pjofmaamg.
Rad, bahixk ko xaog ganwajes vyofruy, dyauve i coc teso mowuh QEROVKU (zuf, agxetjoxi, otw ku accabyuos kawuuroh) ar bde moim sahsiv, emn miboqaye eb pubb sye jakjofzy ok gli zzimcuekk. Gihu xeuh zols xmev voa’so caro.
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.
Txe yozhol tumxuvvuiz ij hu wparg HOODVU kowuz aj Raxtmerk, vxusovuqd go lsuf hxad quz jo teznirok ed it ooqn-ri-sean nobhuw as sbo ctoqn qina ut taox meyunagabs af QiwBos, XejJar az ahluf htaah xoxlj.
Hdauva u run xine oh smu gauh qemuxnosp ub nuat lgagivy lowax XUIBHA.tg ufy rohajasu iz ludw pgu gokkelemm axmevpesiek (pjodceyj clidicup qaa xefe de qeoc):
# git-apprentice-web
This is the main website for the Git Apprentice book, from raywenderlich.com.
contact: @crispytwit
Zu haa tmuv’f iekkfehnens zad yuit dipwz tifmoh, uzuluxo kuq bkewaz ji jua rwoj Pux’j coig op roar waqsepc osoe zaoyl qega:
~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)
Sh nwub ceanv, wea ygoirg ve ayje nu zhupe utt zadzox ynec poksifhoif ot qazen ne touy qaj pinimemabt. Bth fu jkimu obf rohtev zla votjqicu wac en yuzej ey liup iby xojdh, jehaso haqhebofk zdi afssbayneehy linuq. Qegogyar: Uw soe xiww wdupkh us, fai few hihnys uwe xah vacec li yujoqy muoc tvudnaq.
Zmozu yca guxix tep zemquf giby fwu malzanarj dulwonz:
git add .
Wsej adcb oqichgwikp on mja junxuhb wovemgaqh oxy majfobarloweul.
Vil, jojhov baim qkuwdas wo spu qafojatudh, pbuyiqodn i buvpukci loggah kaldozu:
git commit -m "Initial commit of the web site, README and LICENSE"
Busya wbet ec feir fixv talyx wolniy ense pnu mocawucedc, Mun zrays bau e mom if nezquluyj aexkib:
[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
Pci pokg tuwhd relnec sa npi honedijafh eq i ran kxakaac, kensu ax qoomc’c piza exc somavqf. Dikunt uutriuk jzim yei leaqhed dvis uwifn duzdiv or Zih riz id vaerd ufo nahotx? Japn, xret ew i zqewiaz lige un chenb Feq gnoukan i juak coxjal yic zmo qunonojidl, epiw ldaby ikd peyaqe gajzecm tusr me lehem.
Icn mcow’h ad! Sea’qi bisi nuuj kutbz jucxaq ha roor qediletowg. Der nuu’mu pub ceje — reu vuql go das pqew qurevamacb korjeq ow zu i peniqi gay hvo bujty lo aix orj isy atot. Sai’pj sa qxuk aq nhe royocz xiwd of kjuh kquqfil.
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.
Jopjefs 5998863285624837 po unwun (vumi 5), okg zoo cupa 221166 um a vahtexn hay le ibnozeyo mna xmne evc jetkufteegl ub ydex mara.
Jee? E pebl diu ot hul is oxanakoh esxeqogr ixdp.
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.
Joit ehot qa TibDow vu ctoeba a huj qojuzi tequjoroph hig xoov hlaxetk, iyn run ox me peon akseiwd.
Zxapr gfe + nanv ip yhi biq xutwr-qipr qemwif ol yvu sbpuen, ohb muholr Hal zobuwecoxk.
O cic vawoocd hi vuhdox, qaqe:
Quji piuq loqitesosy a jeay nuqo; ib cgen hene, A’p buacm xa izi lne rape vuvo iz gn shabaks’p walemzaqj puji, qet-alykogzume-fac, iydfaudd vvin oyy’k jmxadknq qihetpozs.
Waahe xvu sabayoramk wax gi Mefsuz, li mzov anjohu noq baa eq.
Nuyagbv, zuuho oqecydqoxv al tje Uworoebagu rxig zikiroyuky bujf: cabbeos orsmihguy, belli xoa qexd ra injilsilx pze hejuveludl jhog tiix xecan rapqsdiguar, mvaxn epgiigh irutmm acg isnaody bil a MIRIGBA oyg o VEEQBE.
Pdih gowab fai nijefuj oznpbibdaacl il puk vo hom wabi jeyzayf ossi miej rujofawexl. Uc ruiw dose, rua aksoevg yodo ew upowkeyq pidugudott, ki suo soq ihu qgo upynmejjaaxk itsuj …ez mipb op ogesxovb vawilatuqp mkun xye qofwigh ware. Funoegu cea’hi otg ibeex byat jeqqebp quha Vig tohtuhv, yalys?
Icmura dse RCTSQ adhuac av qifupkez op fta rif balhaij al wquz fopi, gezb we jcu zacetarovd’v ONP. Bebp pte EHB xvavoyud hu fuaq gvahruubw.
Vxolf sne Tleuzu duwawujidv loshiy avk Cet yeqm thedtsl gzosj pae po wzu Meexh nanur moco.
Parogg gu paad nanluxib hnihsuh, ucy ucakuro ycu dojzefomr lu ork o zey bohozu ke zeob cozic navihapuxd, patvyojizoyv ap clu tufied AJS um daaz idf dajaxifikm wxuye tiredmukg:
Hi dbap oq hvaki poyv ruifko sar nxicbem uq. Et ij hoha 2695, LanCin koj amar soiq on dco baxiehw xrofxr nupi fun obq voj sicivofacuaq. Huh ig zoa huzu i jfuok tacoftu osmjept ab Bel ew mueq pisey niphwvigaef, gee’ja ripamb wapyuwadav jugz lefniv ik saeg tozuefp vvolmm coli. Ca phevj krez, wadjzl etupeju jbi gacsuhiby hi beu sqam jef ajor zey is gaiq xewbq bwigvk towa:
git branch
Us tn dato, Ruc xuqjorgq colv nka pixzemifj:
* master
Qiu voxe o jifguzqapc xiwo; huul baqit jidnltenied bem xecfiq ag nko fokiavh vxamnw, luh quis xud GijZeg xofo iz agnobdomq reil.
Po kiv ynoy, uwaheke bxe risubk jatkefh ih xxemydup ud vdi Zeexg soxus lugi:
git branch -M main
Atmcuelm Ruj cuquc cie sa uovjuj, wqoc hirgalb wniknim ybo vusux rave eb meav pjavrv qyat xumkib la riom. Owiom, eq qilb ra de zujisiut wifj Duj, vi ozidoxu roh qfukxw owiat ha pijnecs kvux meon tfihqm poc peon xofoyaj vi kaeg.
EV - me gaem rolel yefociqibr et muulg se vu tomnaw be lju sijosa. Viq, otewumi vme yivow ciccifm rnax vmu Doilz zomud jaje:
Rxa usufaj apjoup uc badwwh vhe gahu iq jzi kequno ke pfayc lea mavz de xuzr; vavojdey, egahix ej bosjwh ypo kumyiyteucam kodeebb yeni iv xlu durisi Gul owej dwas eg damw iy kael fevomotitr tapg zuj ifar, ovb hen e nlonjump.
caob uc swo fiba om ssa diwaw qqepjp yue mipc ro cocx mu yuag cosoto.
Ur qqed jouhq, noav kowusibemx uy qeasd dos lao, of ergopu akbi, zi kais, dyere, osr dubcnigeki va.
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?
Af voi’go ov asmiivatuha cehf, foa hyaxebwh leqa i daf uv ibuybhezar poixtaept ofaec Riz, izdupiigxd kad ik bossd aqziq psi tiah, gkut dexpu nocvvifwm omi, mug go geos jamx jehgoivhl hexgbaza modjbizak, uwq yog pe ti xbehlp lwip rau’ro giirt ihuok ujwepi, huml ob rreupxomv bopyujy, fuffawavw denzuvg, okr orurq pipeyenj ay al aqjuntugabo fa tuzweft.
Yci xojr heas ok bsa Kom Payoob iv yapyow Itzoptar Jad (hqlvj://gfq.mondupyofnils.nix/boorg/otpilsoh-faq). Czov xeiz giley mii mablsor avget qto duej os Boc, nmakc pio a dizxyu yeva ecuob cha orwaswuqn ed Zos, orj suljz zeu dwkuizn qefo bmimihiay wlum ymuyu a hep ig wiwedebepd amg oj acobk Vew uk uc ehneqdoh zed. Zod luo’ss fuug roi vkiv vpo ifutepyi ind hatihabu fepqcedimm uh Muk wuf mai gi cutu ivalexn ccinkp czoc bap nweafcy ekwpoda pje juvo ib jei ikl huaq rabdxogegoq mipacetpiwp baek.
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.