Be sure to install Git version 2.30.0 or higher.
A lot of developer technologies require XCode’s command-line tools, but they are useful in their own right. To install them, you’ll need to pull up the Terminal app on your Mac. The easiest way to do this is through Spotlight Search: click the magnifying glass in the upper right-hand corner of your Mac, and start typing Terminal
; click the result that appears labeled as an Application.
You’ll have a small white window that pops up, with a line that most likely has the name of your computer followed by a colon, tilde, and dollar-sign, e.g., janes-mac:~ $
. There’ll also be a cursor, which may or may not blink.
Type xcode-select --install
(note the space before the two hyphens) and hit the Return/Enter key. (You might be prompted for your admintrator password.) You should see a some output fly by, unless you've installed XCode previously. In that case, you'll get an error informing you that your command-line tools are already installed. Once the script has finished running and you see the dollar-sign prompt again, type git version
and press return. You should see git version 2.30.1 (Apple Git-130)
, or a similar number, output in the Terminal window.
To easily install the very latest version of Git, follow the instructions below for installing Homebrew and then run:
$ brew install git
Don't forget to configure Git once you've got the latest version installed.
Download the Windows installer for Git and double-click the downloaded file’s icon to install it; it’ll probably be in your Downloads folder.
Walk through the Git Setup Wizard, making the following changes from the defaults:
- On the Select Components screen:
- Select "On the Desktop" under Additional Icons
- De-select "Windows Explorer Integration"
- On the Adjusting your PATH environment screen:
- Choose "Use Git from Git Bash only*"
- On the Configuring the line ending conversions screen:
- Choose "Checkout as-is, commit as-is"
Git Setup will then complete the installation; it takes a few minutes. Click Finish when it's done.
Look for the Git
or git-bash
icon on your desktop. Double-click it, and type git version
into the terminal window that opens. You should see output like git version 2.32.0
or some similar number.
If you're running Linux, Git may already be on your system. Run git version
in your terminal shell to see if there's any output. If you get a "Command not found" error, Google around for the preferred method to install or compile Git on your Linux distribution, preferably through your distro's package manager so you automatically receive updates along with the rest of your system.
You'll need to open a terminal window (MacOS/Linux) or Git Bash (Windows), and type the following commands. Replace YOUR NAME and YOUR@EMAIL with the actual name and email you use.
$ git config --global user.name "YOUR NAME"
$ git config --global user.email "YOUR@EMAIL"
When you've run those commands, run git config --global --list
and you should see your name and email. If you do not, re-run the commands above to fix any mistakes you've made.
As of Git 2.28.0, it is essential to configure Git to use a custom default branch name. The default branch had been master
, which Git, GitHub, and the wider industry are moving away from because of its historically racist connotations. main
is now the preferred name for the default branch, and we will use that in this course. To set main
as your default branch for all new repositories that you create, simply run:
$ git config --global init.defaultBranch "main"
If for whatever reason you cannot install at least Git 2.28.0, your best bet is to create an alias for yourself, such as git new
, which you will need to use in place of git init
:
$ git config --global alias.new '!git init && git symbolic-ref HEAD refs/heads/main'
If you have old repositories that you'd like to convert from master
to main
, check out this excellent post's instructions.