Skip to content
Laviyx Learn

Try

Git and GitHub course menu

How to Install Git and Set Up Your Name and Email

Install Git on Windows, macOS and Linux, check the version, set your name and email with git config, choose the default branch name and editor, and open a terminal.

Beginner4 min readUpdated
On this page

Install Git#

Windows: download the installer from git-scm.com and accept the defaults. It includes Git Bash, a terminal that understands the commands used in this course. Use Git Bash for all the lessons.

macOS: run git --version in Terminal. If Git is missing, macOS offers to install the Command Line Tools. You can also use Homebrew:

Terminal
brew install git

Linux (Ubuntu or Debian):

Terminal
sudo apt update
sudo apt install git

Check that it works:

Terminal
git --version
Output
git version 2.54.0.windows.1

Your version number may differ. Any recent version works with this course, though git switch and git restore need Git 2.23 or later.

Tell Git who you are#

Every commit records an author. Set your name and email once per computer. --global means "for all my repositories":

Terminal
git config --global user.name "Asha Rao"
git config --global user.email "asha@example.com"

Use your own name and the email you will use on GitHub. Check what is stored:

Terminal
git config user.name
git config user.email
Output
Asha Rao
asha@example.com

Name the default branch main#

Newer projects call their first branch main. Make that your default:

Terminal
git config --global init.defaultBranch main

Choose an editor#

Git opens a text editor for longer commit messages and some other commands. If you use VS Code:

Terminal
git config --global core.editor "code --wait"

--wait makes Git wait until you close the file. The default on many systems is Vim. If you end up in Vim by accident, press Esc, type :q! and press Enter to leave.

Line endings on Windows#

Windows ends text lines differently from macOS and Linux. The Git for Windows installer sets core.autocrlf to true, which stores files with Linux-style endings and gives you Windows-style endings when you check them out, so teams on different systems do not see every line as changed. Leave it as it is. On macOS and Linux no change is needed.

Terminal basics#

These are the only terminal commands you need for this course:

CommandWhat it does
pwdShow the current folder
lsList files (ls -a includes hidden ones)
cd notesGo into the notes folder
cd ..Go up one folder
mkdir notesCreate a folder
cat notes.txtPrint a file
echo "hi" > a.txtWrite hi to a.txt, replacing it
echo "hi" >> a.txtAdd hi to the end of a.txt

Getting help#

Terminal
git help commit      # full manual page
git commit -h        # short summary of the options

Common mistakes#

Practice#

Practice exercise

Print the value of user.name, and then print the default branch setting.

Show solution
Terminal
git config user.name
git config init.defaultBranch
Output
Asha Rao
main

Key takeaway#

Next: Your First Repository and Commit.

Finished this lesson?