Install Git and check the version
Before anything else, make sure Git is installed on your machine. Most macOS and Linux systems ship with it; Windows users can download it from the official Git website.
Open a terminal and run the version check. If you see a version number, you're ready to go.
# Check that Git is installed git --version # Expected output: git version 2.x.x
brew install git) or apt on Linux (sudo apt install git).Set your identity
Every commit you make records who you are. Configure your name and email once and Git will stamp every future commit with them.
git config --global user.name "[Your Name]" git config --global user.email "[[email protected]]"
The --global flag applies the setting to every repository on your machine. Omit it inside a specific repo to set a different identity just for that project.
Create a new repository
A Git repository (or "repo") is just a folder with a hidden .git subfolder that tracks every change. Let's make one.
mkdir my-project cd my-project git init
Git will reply with something like "Initialized empty Git repository." You now have an empty repo, ready to track files.
Make your first commit
A commit is a snapshot of your project at a moment in time. To commit, you stage the files you want to include and then save the snapshot with a message.
# Create a file echo "# My Project" > README.md # Stage it git add README.md # Commit with a message git commit -m "Initial commit"
Track changes with status and diff
As you edit files, Git keeps watch. Two commands tell you what has changed since the last commit.
# What's changed? git status # Show line-by-line differences git diff
git status lists which files are modified, staged, or untracked. git diff shows the actual line-by-line changes — green for additions, red for removals.
Branch, switch, merge
Branches let you work on a new idea without disturbing the main line of development. When the idea works, you merge it back in.
# Create a branch and switch to it git switch -c new-feature # ... make changes and commit them ... # Switch back and merge git switch main git merge new-feature
git branch -D new-feature and nothing on main is affected.Push to a remote
A remote is a copy of your repo on a server — usually whichever Git hosting provider your team uses. Pushing uploads your local commits so teammates can see them.
# Connect a remote (once per repo) git remote add origin "https://[your-git-host]/[your-account]/my-project.git" # Push the main branch git push -u origin main
The -u flag tells Git to remember the link between your local main and the remote main, so future pushes can just be git push.
You're ready
You now know enough Git to start a project, save your work in commits, branch off for experiments, and share with others. The rest you can learn as you need it.
Three commands you'll use every day: git status to see what's changed, git commit -am "message" to save it, and git push to share it.