Use the below instructions to install and configure Git on your computer.
Installation
Install Git on Windows
## Install Git on πͺ Windows
1. Download the installer at gitforwindows.org
1. Run the installer. Use the default settings, making sure to install Git BASH
1. Proceed to [Configure Git](#configure-git)
Install Git on Mac
## Install Git on π Mac
The Homebrew software package management system simplifies installing software on macOS.
1. Copy and run this whole line to Install Homebrew.
```bash
/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.
2. Confirm that Homebrew was installed. It will print the current version (e.g. `Homebrew 4.4.3...`)
```bash
brew --version
```
3. Then install git using Homebrew
```bash
brew install git
```
4. Proceed to [Configure Git](#configure-git)
Install Git on Linux
## 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](#configure-git).
```bash
sudo apt update
sudo apt upgrade
sudo apt install git
```
Essentials
- Verify Git is installed by outputing the current version.
git --version
# -> git version 2.38.1
- Add your name and email
Replace the below with Your Name (inside the quotes) and email (no quotes) one line at a time. Press return after each line
git config --global user.name "Your Name"
git config --global user.email youraddress@example.com
- Set the default branch to main
git config --global init.defaultBranch main
Other Recommended Settings
- Set pull to merge (recommended over rebase for new users)
git config --global pull.rebase false
Why merge over 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
- Use nano for merge messages
git config --global core.editor nano
- 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