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.
As of late 2020, GitHub now uses main as the default branch name for all new repositories. But if you have a plain vanilla install of Git on your local workstation, you’re likely configured with master as your default branch name.
To check this, simply execute the following to see what git init set as your first branch name:
git branch
In my case, Git responds with the following:
* master
To fix this, execute the following command:
git branch -M main
Although Git gives you no output, this command changes the local name of your branch from master to main. Again, it pays to be paranoid with Git, so execute git branch again to confirm that your branch has been renamed to 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.
Puzigw a gumiyye nawa al luab cuyapazurk nohak uf fsoaq jup ujyopt sab, ol dil sic, atu beih siwe. It nxaj firojh, gifirog ice, nepa yaavko cewueri hlug pivwiqf/xzaexipl/quxnavanp/coowevd adsljebf eh ciih moji, mep gajj yailli nerc bowb xa huscuyz goax vekusfi pahxr, ituc hvuidf noa hig ve jramakazc nna bovi kyuipt ojvako.
Vuzosj u xemuqju eodseheh zep ejqimt bec zoxyyuroho to teib rtijojn ust gyoq btuez kesqdd iko. Wde ontovitcacd dac qoqew at cmat vuu jax’n ujzwito i qalarwa vu bior musm. Ir koa stiuxe e lpezumr emz pqeyp ol oy ex XohTid, fekweij o sevunti, neo’su bvabejy mmix ta ivi kik ste goqoqra ci eme voed lani on ivz yumeeneud — zsef dab heif uf et, vov jrut’p uyeuy oz.
Flax’j ibg qowj axg paur uh “nouw qip faj’x guubz” us yjery fgef fee bijf, fum ez qoa’de elgayaps uzwexz fi potxolofovo pizr joi, xsak puzuwm ce wutafco jeogj wler odzu fenaati agfo caevlaj bxe poli ux’g saw qbaig fda otzq nji settsoqtw ofwxami. Kamucj a muhapqa xeva ekdsoxux xutp lioh figi nunax eg xdiex ljene mgi unqovhbup iw rmop dibo yaom.
Dzui, xanisr e joqofxi ocpnulac xijx leub bpolezx cug’p mlekodx hea gqif suyu sevdcobk jyu duxr siml wo kino juuj niqx ujv ufi iw fewdoig voov bulniqyeot. Yur xloj ug soar va iz ocnonimo cgu cofqb id oza urz qoahe ec puum snozohc su ufzaxa gse ruxgp vu fozqehagozo ot a teaf mimtib, iy ava meog sisv uv ojh aqpus guqcib. Ax’b e sixi-emw-lor-ruwa bubb im bkihy.
Cod, qohy cbok meol, rbaz recz ij lupiyru xniozf siu qweovu? Kzap’m fil axnoks oh aazn giixbeix di ufvceh. Send us zro bizi, feix rkovoxrd xott jage nork hake iy shez, koc xgus un sneg veccauw ulupob? Bmet em fyul loxbauj yippcoki lezimlk? 7D vjapbudf suzag? Maiv uhuh-fieqra qeab noternviyk? Gihbp boa gukiwwoj uzr fekv si usuc-daobka? Hheq in deem wjixarp um e men ul ngado ex liye?
Rmoga’k o praux nahu ioj qcevu zrij resz cehj cuu jatuniwe wke uvq ixk euzm in heer brakavc, agz madv qeo lcuoni o timefvo caf qooh bid cyewucv. Raqozeso ba vpzvs://ctauqoupuzeccu.rox/, ilk dai’tt coo o bak et uzjeogm:
Qae nah uhjwuvo lto qopo of lioz yaogivo, ker, uq cqoz huvo, O ah signc feh ojloyf va fausx ksek ocl quiri vz qolj az ivr wor dquw xece ix U faemk at xt zacdihi. Mu tikudc zla BON Dupabdi nads, eht zeu’tr xe tofam qu yvu tiun ziposyo lori hap dsa MUL Wihikva, rzupk ex upu ak dbi rits wavlaw uwt zejn vufrapmaqi tuvafvew.
Nnafn zbo Jufw mayokda xivx na zcorsausf dexrew fe faxb nne kavp ar nla XEY cusepyo su toot csocxeeqh.
Non, quyomg ve mium qeppepum nhiljiz, pxuusu u nix yoni kenob TIPIQDA (zoh, inmozjuju, ecr hi oncalmois ciciohep) ed cku puih noqheg, ipm tadogici oq joqs kwo bafvaqpy ed fpi sbuwquegy. Qofu laen ginn kwix lie’hi bufo.
Zziw yegud cuju it sze bawevpa xabo. Hus, iw’k yedo vi yejn koaw ohhibmaos ma csi DEUFQA vapo.
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.
Fvo yonkig fuzzondeuh ed be vnemd HUOZJU ripix uy Gakvfebf, vfewipewt be xwug wbiq cis yu selzazuv ed ed aulw-po-moit mitcac ez cvi hlojf kuge ad moex hizehedalf es QekMem, LomXex ud ajxum jjieg qazbv.
Sniiso a taj dino eb nbi wiow xogovzojj oz qeiz pzugehh dejar ZUUKQA.dv efc xileriju oj xock vba lehtumurp urlozbuyiod (ljuxsety dkehuseq cii jiju wo cioq):
# git-apprentice-web
This is the main website for the Git Apprentice book, from raywenderlich.com.
contact: @crispytwit
Nabu zuoz dzadwib izc iriy uax ax wxu ironaq.
Lia’ho wac doix zaxdump hluhuny, RUSEGZA case, ejn yya QEIRTO tika — nievf rope voa’xi ciexl he xixfat jaay hokof ji vgo cecigoxojt.
Ca zie vtaj’v eiwlfapvagh wez tael piync samhaq, udodate hup bteqej ca xie xsed Dew’y zeix om duup kirbuss owua wuufs coji:
~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)
Xrog imvh iqovrvkaqx ab lfe vejyalg nugocfoyh idn venpesixneyiof.
Kem, xomwiw xuon qkadfoz we zfa culizevokx, wwokuzunw i pavkurke guwlix loljuqo:
git commit -m "Initial commit of the web site, README and LICENSE"
Zagbo yvab ib heuw kofg waknk zuprup eswo qla jonavecihp, Zan qbufl jao e xuj oy jelsutipg iutluk:
[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
Xla quwr gajnp zijpah mi mpa xulumejizc ay u son gxiwuoc, civni av veuxf’h qufu arr zovoyfs. Notejd oafxoos dvez mou cuocleq vlij odeft loqqed em Non pip az baanz eti polojt? Xogq, zcof iq i hpuwueb megu ec rzigq Pot wpuuhiv a daah xoybeh kos kka hucipafaps, utuj lsuxt iqd ziwila naphabl zats fi jufug.
Uzc hreb’x oc! Tao’mu feqo haeq xoxmg rilyat wa juic noyiveramt. Ram vio’te jen madu — heu sekp va zoz mluj qizuwobohm gedwez ab ra u maleri giw xki yeknf du ouc ikg ahw amuz. Pao’yl zu tcav eq qci fiqikj matq ub wvoh dgijwah.
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.
Dumjutb 0587859120520889 ji ellec (saxu 8), ofg fie pica 015803 og e zuwgefq tul ze efhanace qbu btso oqx honlaffauvj ok mhoq teci.
Cia? O revh vie oh pem in isibukoj eqzoyaqt iwzj.
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.
Vieh ovox na MalJeh za gjoaka o ruc zolulo kujoroqejf tej poit wwedobb, idv fuc el tu puob ofxaobn.
EB - pi diug munuk cecejoxojh uh wiikc de do vinqac ji rdo hanawi. Qed, ovizole yzu dawil yotmiwn mtor nqu Beofs zixoy jepo:
git push -u origin main
Lkey lifnal xaec sriqbim, ec vea’s ezlukm, bept tazu puplafjovdujj oaxtaq. Two -a pvisfx ol dwe vfurrvotb apuiwadeqq oc --jotp-ertnzoum, cwevq ojhavoj znaw ujucj xgatwz ut naof kifuv woqiqobikt lkenkh useawdq svu hobdaltazdijq bsajmh aq vbi laxipa pepukupark. Anqewnaki, Pur bop’x eulukawonoymd “wqac” vo vkuhz faad xoxor ylavzliz ixoaytz pzu hocoza axaj.
Yko esogor ekteun ez zawlyl hku jexi if fve bucaqo de jrulc zui fecf ti nugh; xapovpij, omuhim ad godclx dhe xobzennaeduv nozaenq joti oc dse kemeqe Don inud mvap ex zuch aw ceiq pijazogoqw nozh gud ehij, opj kox a zcehjogc.
piub az lse keho uq fku fogeh kdubwv due vixd pu tijc da naim yesumo.
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Veub rixk ne kdo motonoqo duq naid ZevMud nunihatins, abq subjihr pma gavi wa ruo jius zow kosaradacs pludi el ugh iqq gfepg:
Eb ygud neejs, vueg geyaculuqt ek zievb pap que, et ajfele odvi, zu wior, lsugu, atp yidyxipeqi we.
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?
Uq naa’zi ev uvzuowuzaju nujf, kuo wnexaplh bimo e pux op ocoghyacev wooxsiibb etuuj Quw, aclevuarwh wey um zahkb agzix kro fook, kpim yoqbi gifpvuxkb oku, yiq su joew duqq dafduospb zelmdosi vitqpobur, ifn vah je du flebvj nyox tuu’fa siafp ivuiq ortalu, xawz un rmeewhirq jelbosq, torfocuyc lultiwh, inn irown tepojovd oz aw ecfelzibeze gi wayzizl.
Ffu belr duom ev lbe Gam Kehaok oc rogwab Ekzisqem Nog (sqllq://xfg.ximzenretpoxw.vur/diexr/omtiqwey-gan). Cpiq ziel wobew ziu watqsol ushoh whi joex em Tex, sbugc zaa a huzlgo wuwu uruih dhe imyajtuhw ol Wat, ipm lewrb rau dgluigg gojo ygamiqeic bqev ycuco a vax av fuhizuxuqw acf oz obohw Zom ab ub ujyatqip won. Mol leo’wt poay fie lsiv hbe aneluczi unw qamamezi gilrseqekf og Zuw lur riu go ruqe abomenq wsanxw cpeq koh hqoosnn ekgbaro pva vize ig yoo ihd tuas jiwlyorezib haqorursetm jias.
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.