Before Orbit gets its first commit, Git needs to be installed and to know who you are. Every commit carries an author name and email, so a few minutes of setup now saves you from a history full of root@localhost later. This lesson installs Git, configures it the way most teams expect and prepares access to a hosting service.
Check whether Git is already there
Many systems already ship Git. Open a terminal and ask for its version:
$ git --version
git version 2.56.0
If you see a version, you can skip to the configuration section, although updating is worth it if the number is far below 2.56. If the command is not found, install Git for your system below.
Windows
- Download Git for Windows from git-scm.com, or install it from a terminal with
winget install --id Git.Git -e. - Run the installer. The defaults are good; choose your editor on the “default editor” screen (Visual Studio Code is a common pick) and keep “Git Credential Manager” enabled.
- Open Git Bash or a new PowerShell window and run
git --version.
Git for Windows includes Git Bash, a small Bash environment where the commands in this course work exactly as shown. If you work inside WSL, install Git inside the Linux distribution too, with the Linux commands below: WSL and Windows each have their own Git and their own configuration.
macOS
macOS offers to install Apple’s command line tools, which include Git, the first time you type git:
$ xcode-select --install
Apple’s build is often a few versions behind. For the latest release, use Homebrew:
$ brew install git
$ which git
/opt/homebrew/bin/git
$ git --version
git version 2.56.0
If which git still shows /usr/bin/git, open a new terminal so your PATH picks up the Homebrew version first.
Linux
Use your distribution’s package manager:
$ sudo apt update && sudo apt install -y git # Ubuntu, Debian
$ sudo dnf install -y git # Fedora, RHEL, Rocky, Alma
$ sudo pacman -S git # Arch
$ sudo apk add git # Alpine
Long-term support distributions sometimes package an older Git. On Ubuntu, the official Git maintainers PPA gives you the current release:
$ sudo add-apt-repository ppa:git-core/ppa
$ sudo apt update && sudo apt install -y git
Tell Git who you are
Set the name and email that go into every commit you create. Use the email your hosting account knows, so commits are linked to your profile.
$ git config --global user.name "Ana Souza"
$ git config --global user.email "ana@orbit.dev"
Without these, Git refuses to commit and prints “Please tell me who you are”. It is not a security feature: anyone can type any name. Lesson 17 shows how to sign commits so others can verify they really came from you.
Choose your editor
Some commands open an editor: a commit without -m, an interactive rebase, git history reword. Pick one you know how to save and close:
$ git config --global core.editor "code --wait" # Visual Studio Code
$ git config --global core.editor "nano" # simple terminal editor
$ git config --global core.editor "vim" # if you already know Vim
The --wait flag matters for graphical editors. Without it, VS Code returns control immediately, Git sees an empty message and aborts the commit.
Use main as the default branch
New repositories have always started on a branch called master. Most hosting services and teams now use main, and Git 3.0 will make main the default. Choose it now so your local repositories match:
$ git config --global init.defaultBranch main
A few settings worth having
$ git config --global pull.rebase false # make "git pull" merge, and stop the warning
$ git config --global push.autoSetupRemote true # first push of a new branch sets its upstream
$ git config --global fetch.prune true # forget remote branches that were deleted
$ git config --global merge.conflictStyle zdiff3 # clearer conflict markers (lesson 5)
$ git config --global rerere.enabled true # remember how you resolved a conflict
Each of these is explained in the lesson where it matters. They are safe defaults that many experienced users set on day one.
Where settings live
Git reads configuration from three levels. A more specific level overrides a broader one:
| Level | File | Flag | Applies to |
|---|---|---|---|
| System | /etc/gitconfig | --system | Every user on the machine |
| Global | ~/.gitconfig | --global | Every repository of your user |
| Local | .git/config in the repo | --local (default) | One repository |
A typical use of the local level: a work email for company repositories and a personal email everywhere else.
$ cd ~/work/orbit
$ git config user.email "ana.souza@company.example"
$ git config --list --show-origin | grep user.email
file:/home/ana/.gitconfig user.email=ana@orbit.dev
file:.git/config user.email=ana.souza@company.example
The last value listed wins. Lesson 15 shows includeIf, which switches identity automatically by folder.
Tip: Git 2.46 added clearer subcommands: git config set user.name "Ana Souza", git config get user.name, git config list and git config unset. The classic forms used above still work everywhere and are what you will see in most documentation.
Connect to GitHub or GitLab
You will push Orbit to a hosting service in lesson 7. There are two ways to authenticate:
- HTTPS with a credential helper. On Windows and macOS, Git Credential Manager opens a browser login once and stores a token in the system keychain. Never paste passwords into URLs or plain text files.
- SSH keys. Generate a key pair, upload the public key to your account and Git uses it silently.
$ ssh-keygen -t ed25519 -C "ana@orbit.dev"
$ cat ~/.ssh/id_ed25519.pub # paste this into GitHub or GitLab, under SSH keys
$ ssh -T git@github.com
Hi ana-souza! You've successfully authenticated, but GitHub does not provide shell access.
The SSH keys lesson of the Linux Tutorial explains key types, passphrases and the SSH agent in detail.
Line endings across operating systems
Windows ends lines with CRLF, Linux and macOS with LF. In a mixed team this shows up as diffs where every line changed, or shell scripts that fail with bad interpreter: /bin/bash^M. The robust fix is a .gitattributes file committed in the repository, so it applies to everyone regardless of their settings:
* text=auto
*.sh text eol=lf
*.ps1 text eol=crlf
*.png binary
text=auto lets Git normalise text files to LF in the repository. The other lines force the line endings that each kind of file needs.
First-time checklist
| Step | Command |
|---|---|
| Git is recent | git --version |
| Name and email | git config --global user.name / user.email |
| Editor | git config --global core.editor |
| Default branch | git config --global init.defaultBranch main |
| Access to hosting | ssh -T git@github.com or a credential manager login |
| Review everything | git config --list --show-origin |
Exercise
You just sat down at a new laptop. What is the first command that tells you whether Git is installed and how old it is?
Show answer
Answer: C. git –version prints the installed version, or fails with “command not found” if Git is missing. The other commands assume Git is already there.
Exercise
You set core.editor to “code” without –wait and run git commit. The commit aborts with “empty commit message”. Why?
Show answer
Answer: D. Graphical editors return control to the terminal right away. –wait tells VS Code to block until you close the file, so Git reads the message after you have written it.
Exercise
Orbit’s repository must use your company email, while all your other repositories use your personal one. What do you run inside the Orbit repository?
Show answer
Answer: A. Without a level flag, git config writes to the repository’s local .git/config, which overrides the global value for that repository only.
Key takeaways
- Check for Git with
git --version; install with winget or Git for Windows, Homebrew, or your Linux package manager. - Set
user.nameanduser.emailbefore your first commit; they go into every commit you create. - Set an editor (with
--waitfor graphical ones) andinit.defaultBranch main, the default in Git 3.0. - Settings live at system, global and local level; the most specific wins, and
--show-originshows where each comes from. - Use SSH keys or a credential manager for hosting access, and a committed
.gitattributesfor line endings.
FAQ
I installed Git on macOS but git –version still shows an older version. Why?
The terminal is finding Apple’s Git at /usr/bin/git before Homebrew’s. Open a new terminal, and check that /opt/homebrew/bin (Apple silicon) or /usr/local/bin (Intel) comes before /usr/bin in your PATH.
Should I use Git for Windows or Git inside WSL?
Use the Git that belongs to the files you edit. For projects stored in the Windows filesystem and edited with Windows tools, use Git for Windows. For projects stored inside WSL’s Linux filesystem, use the Linux Git inside WSL. Mixing them on the same folder causes slow commands and line ending surprises.
What does “Please tell me who you are” mean?
Git has no author name or email for the commit. Set user.name and user.email with git config --global and run the commit again.
Can I change my name or email after making commits?
Yes, for future commits: change the setting and new commits use it. Commits that already exist keep the old values because changing them would change their IDs. For commits you have not pushed yet, git commit --amend --reset-author fixes the latest one.
Is HTTPS or SSH better for connecting to GitHub?
Both are secure. HTTPS with Git Credential Manager is easiest on Windows and macOS and passes through most corporate proxies. SSH keys are common on Linux and servers. Many teams also use SSH keys to sign commits, which lesson 17 covers.
Why does my shell script fail with “bad interpreter” after cloning on Windows?
The file was checked out with CRLF line endings. Add *.sh text eol=lf to .gitattributes, commit it, then run git add --renormalize . and commit again so the script is stored and checked out with LF.