Install Git
Use the below instructions to install and configure Git on your computer.
Install Git on Windows
- Download the installer at gitforwindows.org
- Run the installer. Use the default settings, making sure to install Git BASH
- Proceed to Configure Git
Install Git on Mac
Homebrew is a software package management system that simplifies the installation of software on macOS
- Copy and run this whole line to Install Homebrew.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
If offered to “Install Command Line Developer Tools”, choose yes, then continue. The Terminal won’t show characters while typing passwords. Backspace several times if you make a mistake.
- Confirm that Homebrew was installed. It will print the current version (e.g.
Homebrew 4.4.3...)
- Then install git using Homebrew
- Proceed to Configure Git
Install Git on Linux
Most Linux systems – including Ubuntu and Raspberry Pi OS – are Debian-based.
Use the Advanced package tool (APT) to install Git then proceed to Configure Git.
sudo apt update
sudo apt upgrade
sudo apt install git
- Verify Git is installed by outputing the current version.
git --version
# -> git version 2.38.1
- Add your name
Replace Your Name (inside the quotes). Press return after each line
git config --global user.name "Your Name"
- Add your email
git config --global user.email youraddress@example.com
- Set the default branch to main
git config --global init.defaultBranch main
- Set pull to merge (recommended over rebase for new users)
git config --global pull.rebase false
Merge vs. Rebase
> Merging is nice because it’s a non-destructive operation. The existing branches are not changed in any way. This avoids all of the potential pitfalls of rebasing. [...] On the other hand, this also means that the feature branch will have an extraneous merge commit every time you need to incorporate upstream changes
https://www.atlassian.com/git/tutorials/merging-vs-rebasing
- Mac or Linux should convert line endings to
LF (see also Configuring Git to handle line endings)
git config --global core.autocrlf input
Windows users should use the following to auto-convert CRLF line endings into LF when you commit
git config --global core.autocrlf true
- Confirm your global settings were saved
Other Git configuration tips
Other tips
- [View settings and location of other config files](https://stackoverflow.com/a/46986031/441878) (system, global, local)
```bash
git config --list --show-origin
```
- Display the contents of the configuration file
```bash
cat ~/.gitconfig
```
References