MarzleyTech Learn

Home / Learn / Git & GitHub / Installing and setting up Git (Windows, Mac, Linux)

Installing and setting up Git

Before your first commit, install Git and tell it who you are. This takes five minutes and you only do it once per computer.

Install

SystemHow
WindowsDownload from git-scm.com, run the installer. The defaults are fine; choose VS Code as the default editor if you use it. You also get Git Bash, a Linux-style terminal.
macOSOpen Terminal and run git --version. If it isn't installed, macOS offers to install the developer tools. Or brew install git.
Ubuntu / Debiansudo apt update && sudo apt install git
AndroidThe Termux app: pkg install git (yes, you can learn Git on a phone)

Check it worked:

Terminal
git --version

Tell Git who you are

Every commit records an author name and email. Use the same email as your GitHub account so your commits link to your profile.

Terminal
git config --global user.name "Amina Hassan"
git config --global user.email "amina@example.com"

Recommended settings

Terminal
git config --global init.defaultBranch main      # new repos start on "main"
git config --global core.editor "code --wait"    # use VS Code for commit messages
git config --global pull.rebase false            # pull merges (simplest for beginners)
git config --global core.autocrlf true           # Windows only: handle line endings
git config --global color.ui auto

See everything you've set:

Terminal
git config --list --show-origin

Connecting to GitHub: HTTPS or SSH

Option 1: HTTPS (easiest). When you first git push, a browser window asks you to sign in to GitHub (Git Credential Manager on Windows/macOS). On Linux, create a personal access token on GitHub (Settings → Developer settings) and use it instead of a password.

Option 2: SSH keys (no passwords, great for servers).

Terminal
ssh-keygen -t ed25519 -C "amina@example.com"     # press Enter to accept defaults
cat ~/.ssh/id_ed25519.pub                         # copy this public key

On GitHub: Settings → SSH and GPG keys → New SSH key, paste it. Then test:

Terminal
ssh -T git@github.com

Use SSH addresses like git@github.com:amina/portfolio.git when cloning.

Never share your private key (id_ed25519 without .pub). The .pub file is the one you give out.

The three places your files live

AreaWhat's thereCommands
Working directoryFiles as you edit themedit, save
Staging areaChanges chosen for the next commitgit add
RepositorySaved snapshots (commits)git commit
Terminal
git status           # what's changed, what's staged
git add index.html   # stage one file
git add .            # stage everything in this folder
git commit -m "Add contact section"
git log --oneline    # history, one line per commit

Git in VS Code

VS Code has Git built in: the Source Control icon on the left shows changed files, a + to stage, a message box and a ✓ to commit, and a button to push. It runs the same commands for you. Learn the commands first, then use whichever is faster.

Why every developer needs Git

Git records every version of your code, lets you undo mistakes, work on new features without breaking what works, and collaborate with other developers without emailing zip files. Almost every software company, startup and open-source project uses Git, usually with GitHub, GitLab or Bitbucket. Employers expect you to know it, and your GitHub profile often acts as a portfolio when applying for developer jobs and internships.

Your first repository from start to finish

Terminal
mkdir duka-website && cd duka-website
git init                              # create a new repository (adds a hidden .git folder)
echo "# Duka website" > README.md
git status                            # README.md is "untracked"
git add README.md                     # stage it
git commit -m "Add README"            # save a snapshot
git log --oneline                     # see the history

Then connect it to GitHub:

Terminal
# create an empty repository on github.com first (no README), then:
git remote add origin git@github.com:yourname/duka-website.git
git branch -M main
git push -u origin main               # -u remembers the link for future pushes

After this, git push and git pull are enough.

Cloning an existing project

Terminal
git clone https://github.com/someone/project.git
cd project
git log --oneline -5                  # last five commits

git clone downloads the whole history, not just the latest files, so you can work offline.

Setting up SSH keys step by step

SSH keys let you push without typing a password or token each time.

Terminal
ssh-keygen -t ed25519 -C "you@example.com"     # press Enter to accept the default location; add a passphrase
cat ~/.ssh/id_ed25519.pub                       # copy this PUBLIC key
# GitHub → Settings → SSH and GPG keys → New SSH key → paste
ssh -T git@github.com                           # test: "Hi yourname! You've successfully authenticated"

Never share the private key (id_ed25519 without .pub). If a laptop is lost or stolen, delete its key from GitHub settings.

HTTPS with tokens

If you use HTTPS, GitHub requires a personal access token (not your account password) for pushing. Git Credential Manager (included with Git for Windows) handles sign-in through the browser and stores credentials securely.

Useful configuration

Terminal
git config --global init.defaultBranch main
git config --global core.editor "code --wait"      # use VS Code for commit messages
git config --global pull.rebase false              # merge when pulling (simple default)
git config --global core.autocrlf true             # Windows: handle line endings
git config --global alias.st status                # shortcut: git st
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --list --show-origin                    # see all settings and where they come from

Aliases save typing: git lg shows a branch graph.

Understanding status output

StatusMeaningNext step
UntrackedNew file Git doesn't know aboutgit add file
Modified (not staged)Changed since the last commitgit add file or git restore file to discard
StagedWill be in the next commitgit commit or git restore --staged file to unstage
CleanNothing to commitKeep working
Terminal
git diff                  # changes not yet staged
git diff --staged         # changes staged for the next commit
git restore index.html    # throw away unstaged changes in a file (careful!)
git restore --staged index.html   # unstage but keep changes

Undoing common mistakes

MistakeFix
Typo in the last commit message (not pushed)git commit --amend -m "New message"
Forgot a file in the last commit (not pushed)git add file then git commit --amend --no-edit
Want to undo a pushed commit safelygit revert <commit> (creates a new commit that reverses it)
Want to go back and look at an old versiongit switch --detach <commit> then git switch main to return
Deleted a file by accident (not committed)git restore file

Avoid rewriting history (amend, reset, rebase) on commits already pushed and shared with others.

Git on Windows, macOS and Linux: notes

  • Windows: Git for Windows includes Git Bash, a terminal with Linux-style commands. VS Code's terminal can use it.
  • macOS: run git --version; if missing, macOS offers to install the Command Line Tools.
  • Linux: sudo apt install git (Ubuntu/Debian).
  • Phones: you can browse repositories in the GitHub mobile app; serious work needs a computer.

GitHub profile tips for job seekers

  • A clear profile photo, name, location (e.g. Nairobi, Kenya) and short bio.
  • Pin your 4 to 6 best repositories.
  • Every project has a README with a description, screenshots, how to run it and a live demo link.
  • A profile README (a repository named the same as your username) introduces you.
  • Regular, meaningful commits matter more than a green contribution graph full of trivial changes.

Practice

  1. Create a repository, make three commits, and view them with git log --oneline.
  2. Set up SSH keys and push the repository to GitHub.
  3. Create aliases for status and a graph log.
  4. Make a change, stage it, unstage it with git restore --staged, then discard it.
  5. Amend the last commit to add a forgotten file.
Think about it: You committed a change, pushed it, and your teammate already pulled it. Now you realise it broke the login page. Should you use git reset or git revert, and why?Show answer

Use git revert <commit>. It adds a new commit that undoes the change, keeping history intact for everyone. git reset rewrites history; after pushing, it forces teammates to deal with conflicting histories and can lose work.

Check yourself

  1. Which command shows your installed Git version?

    Show answer

    git --version

  2. Which setting stores your name for commits? (write the config key)

    Show answer

    user.name

  3. Which file do you upload to GitHub: id_ed25519 or id_ed25519.pub?

    Show answer

    id_ed25519.pub

  4. Which command stages every changed file in the current folder?

    Show answer

    git add .

  5. Which command shows history, one line per commit?

    Show answer

    git log --oneline

  6. Which command creates a new Git repository in the current folder?

    Show answer

    git init

  7. Which command safely undoes a pushed commit by creating a new commit?

    Show answer

    git revert

  8. Which command fixes the message of the last commit that hasn't been pushed? (two words after git)

    Show answer

    commit --amend

  9. Which command downloads a repository and its history from GitHub?

    Show answer

    git clone

Lesson 2 of 12 in Git & GitHub · Written by · Course notes