Set up Git and GitHub: install, identity, SSH keys, GitHub CLI and your first repository
Install Git on Windows, macOS or Linux, set your name and email, create a GitHub account with two-factor authentication, connect with SSH or the GitHub CLI, and create and clone your first repository.
Key ideas
How it works
1. Install Git
| System | How |
|---|---|
| Windows | Download Git for Windows from git-scm.com and keep the defaults (it includes Git Bash and Git Credential Manager). Or run winget install --id Git.Git -e. |
| macOS | Run git --version; macOS offers to install the Command Line Tools. Or brew install git. |
| Linux | sudo apt install git (Ubuntu/Debian) or sudo dnf install git (Fedora). |
Check it worked:
$ git --version
git version 2.43.02. Tell Git who you are
git config --global user.name "Your Name"
git config --global user.email "[email protected]" # use the email on your GitHub account
git config --global init.defaultBranch main
git config --global pull.rebase false # or true, if your team prefers rebasing
git config --list --show-origin # see every setting and where it came from3. Create your GitHub account safely
- Sign up at github.com with a professional username (it appears in your portfolio links).
- Turn on two-factor authentication: . Use an authenticator app or a passkey, and save the recovery codes.
- Add a profile photo, bio and a profile README (a repository named exactly like your username).
4. Connect with SSH (recommended)
ssh-keygen -t ed25519 -C "[email protected]" # press Enter for the default file, add a passphrase
cat ~/.ssh/id_ed25519.pub # copy this PUBLIC key
# GitHub: Settings > SSH and GPG keys > New SSH key > paste > Add
ssh -T [email protected] # "Hi <username>! You've successfully authenticated"Never share the private key (the file without .pub). Use one key per computer, and delete keys for computers you no longer use.
5. Or use the GitHub CLI
# install: winget install --id GitHub.cli | brew install gh | see cli.github.com for Linux
gh auth login # choose GitHub.com, HTTPS or SSH, and log in with your browser
gh repo create study-notes --public --clone --add-readme
cd study-notes && git log --oneline6. Your first repository from scratch
Here is a real first session: create a folder, start Git, and see what status reports.
$ git init
Initialized empty Git repository in /home/asha/notes/.git/
$ git config user.name "Asha Learner"
$ git config user.email "[email protected]"
$ echo '# My study notes' > README.md
$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)$ git add README.md
$ git status --short
A README.md
$ git commit -m "Add README with the course title"
[main (root-commit) 5e9b349] Add README with the course title
1 file changed, 1 insertion(+)
create mode 100644 README.md
$ git log --oneline
5e9b349 Add README with the course titleTo put it on GitHub, create an empty repository on github.com (no README), then follow Lesson 5 to add the remote and push.
Common mistakes and fixes
| Mistake | Fix |
|---|---|
| Commits show the wrong name or email | Set user.name and user.email globally, and fix a single repository with git config (without --global). |
| Typing your GitHub password in the terminal | GitHub does not accept account passwords for Git; use SSH, the GitHub CLI, or a token via the credential manager. |
| Sharing the private SSH key | Only the .pub file is shared. If a private key leaks, delete it on GitHub and create a new one. |
Practice
- Install Git, set your name and email, and run git config --list --show-origin.
- Create an SSH key, add it to GitHub and run ssh -T [email protected].
- Create a public repository called study-notes with gh or the website and clone it.
Quick check
Which command sets your name for every repository?
git config --global user.name "Your Name"
Which part of an SSH key do you paste into GitHub?
The public key (the .pub file).
Why turn on 2FA?
It protects your account and code; GitHub requires it for code contributors.