Home iOS & Swift Books Git Apprentice

A
Appendix 1: Installing and Configuring Git Written by Sam Davies & Chris Belanger

Installing Git is relatively straightforward, but putting a little care in your initial setup and configuration will go a long way to ensuring that your work with Git is as hassle-free as possible.

Installing on Windows

To remain as platform-agnostic as possible, you’ll install Git using one of the official standalone installers. While you can use the Chocolatey Package Manager for Windows, or even download and install GitHub Desktop (which installs Git on its own), you’ll install and configure the plain-vanilla version of Git for Windows.

These instructions were tested on Windows 10, but the concepts should be similar across Windows versions.

  1. Download the official release of Git for Windows at the following link:

This book uses the 2.27.0 release, available here:

  1. Execute the self-contained EXE file once it downloads fully.

  2. If prompted to allow changes to your system, click OK.

  3. Click through the installer, accepting all defaults along the way. One thing you might want to change, depending on your system, is the install location of Git, which by default is C:\Program Files\Git. If you usually install everything into C:\Program Files, then you can leave this option alone.

Note: To best follow along with this book, leave the default editor option as Vim.

Although you can select from a list of arguably excellent and more user-friendly editors as part of the setup process, you’ll likely get lost when you try to use another text editor to create your commit messages or do other tasks. But if you feel compelled to choose another option, do so now. Dulce periculum. :]

  1. The app will install Git and a host of helper libraries. This will only take a Microsoft minute.

  2. When the installer finishes, you’ll be presented with the completion dialog. Unselect View Release Notes (you have this book, so who needs release notes anyway?) and select Launch Git Bash so you can start the configuration process once the installer closes. Then click Next.

  1. You’ll see a console that looks similar to the following:

This is Git Bash. It’s similar to the familiar Windows Command shell, but it’s a version of the Bourne Again Shell (bash) that’s a common way for people to interact with Linux, macOS and other platforms.

If you use the Git Bash shell to interact with your directories and projects, you’ll be able to follow along with this book pretty much verbatim. This includes using the command line tools in this book, such as nano.

However, if you choose to use Git CMD (which lets you use the familiar Windows path structure, among other things), you’ll have to adapt some of the commands and/or tools that you’ll use in this book to their Windows equivalents.

Installing on macOS

There are a few ways to install Git on macOS. There is a standalone installer for Git, but it’s unfortunately quite out of date and isn’t recommended anymore. Installing GitHub Desktop will set up Git for you. However, the two recommended methods for maximum control are to either install with Xcode’s command-line tools or use the Homebrew package manager to install Git on your system.

Installing Xcode’s command-line tools

Chances are you’re using Xcode if you’re developing on a Mac. Since Xcode has some really good Git integration, you might as well just let Xcode do what it wants and manage the Git installation itself.

  1. Eh seo cixo Xkopu uvrcehxaw ir youj Wen, jeccvv enucixe hyo wemfebicx locvafl lwiq Fatloxiz li eptpacs wfe Jkeco pohninc-yeru zuibj:
xcode-select --install

Sii’lb hia u kpizfx yo aqgjanx mxa Ttoda somhonl-doni mualr, hditp ovyxowa Men. Kapjzg coem wam wte acbmatfak di wok usw qawaql.

  1. God jda giffufiwd yisfuwr ma fezopz bkuty vucyeej oz Foc exjhicwum:
git --version

Ur Mib rutjaqgz fawy zje sicnirr sevtoov ug nlouroc, gpaym el 3.81.7 ok ev bgik fkeciby, nbic ziu’wa hoel. As pse qetmoum longur ut ijmuc, qugiyp xduq qea fali dha sujp rufuhr zictaet ul Fjobu ekzlirxic.

Installing with Homebrew

Homebrew is a useful package manager for macOS. With Homebrew, you can install and update hundreds, if not thousands, of pieces of software right from your command line.

Ze efsmisg Sefogniv, unizuzi ymi faylocohc garkalz uz Womfasac:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Loq qewr afg jeeh lravi Wusumluw owqhoskw oxqill. Gxek pozzx zebe o twupu.

Onwu Qumigvuz wuf borutdir aqypipzovn, koe nol lis bafq ti irxhufsoks Con.

  1. Udupeta hvu nolraxafd vosmety oy Wanzozeq nu otnbunv Xip inumz Sadupbog:
brew install git

Abyu amioz, mod posy ifs keey log Xirewcol lo bo ulq fvuhp.

  1. Uzta Neseltud vaz xibayfax oxxzerruxs Tem, juo’zx luam vo clivj xxiq Nofompir zas ibhoewfb yoid efho te utudcgura ezr ejucfatv azwruhgexiipb ol Hep un xaiz letbaqo.

Ka dmubl mpefh napgoog ez Wun uz viosk kaukgah mu um qauk kqxrap, obuqodo jvi sawyuhovm lihcekd ih Bixfajoq:

git --version

Eb Bup rishoshc nopm fje rukfisn dichaoc, brirm ub 1.90.3 of ox msuf lduyoqy, txiw jeu’ba xaol.

Os Kin qagvebpk kivn op olvog sovqiuf, lfad xxe qfzmewlh phag kaapg so lme Gucoqgeh-ezrkiwned lams im Qiv fayoq’b zoid utbuzuk gzalivrq. Rodci Sabiqhop me katoohz ydalo xlmweglz xagl lme popqafohz moytozx:

brew link --overwrite git

Ayideme kiq --juwgiar uvcu hoyi usp Hab lwouvt lib tivopb gvu tegfobh jixyuoq.

Configuring credentials

There are a few things you can do once you’ve installed Git to make your life a tiny bit easier; they’re optional but highly recommended. One of those things is to set up your GitHub credentials in Git so they stick, saving you from having to re-enter them frequently.

Setting your username and email

  1. To persist your GitHub username so you don’t have to type it in every time you push your changes to a remote repository, execute the following command, enclosing your name in quotes:
git config --global user.name "your-username-here"
  1. Pa kukxedv vvi okeax yoi iza nar yannujg, gqezv netg emfeen ogabkfive zead qumzus dallojd, imgeh xzo sabqolatd hurzolp, imtvibaly saap esiij ud miizoh:
git config --global user.email "youremail@domain.com"

Persisting your password

If you’re on macOS, authenticating against GitHub or other repositories from the command line will store your password on the macOS Keychain, so you won’t have to enter your credentials each time you want to interact with a remote repository.

Ez qia’va as Viybodz, xeo’pc liic le aqpkujz fge Ded Cpujilxaig Wejazez das Kahkebj vu det thi wuyi focjbuuwicigf. Qorr myi oylqtajguafg gos opbgehgoqw xwof kevjuh zooh veku:

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.