tech

10 Basic Git Commands Every Beginner Should Know (With Examples)

Git is a powerful version control system, but getting started doesn’t require memorizing dozens of commands. By learning a few essential Git commands, you can confidently manage your code, track changes, and collaborate with others.

In this guide, we’ll cover 10 basic Git commands, explain what they do, and show simple examples for each.

1. 'git init' - Initialize a Repository

This command creates a new Git repository in your project directory. It sets up all the necessary Git files to start tracking changes.

git init

What it does:

  • Creates a hidden '.git' folder

  • Turns your current directory into a Git repository

2. 'git status' - Check Repository Status

'git status' shows the current state of your working directory and staging area.

git status

What it does:

  • Shows modified files

  • Shows untracked files

  • Indicates what’s staged for commit

3. 'git add' - Stage Changes

This command stages files, preparing them to be committed.

e.g., add a single file:

git add index.html

e.g., add all files:

git add .

What it does:

  • Moves changes to the staging area

  • Does not save changes permanently (that’s what commits are for)

4. 'git commit' - Save Changes

A commit records a snapshot of your staged changes with a message.

git commit -m "Initial commit"

What it does:

  • Saves changes to the repository history

  • Associates changes with a message and author

5. 'git log' - View Commit History

This command displays a list of all commits in the repository.

git log

What it does:

  • Shows commit IDs, authors, dates, and messages

  • Helps track project history

6. 'git branch' - Manage Branches

Branches allow you to work on features without affecting the main code.

e.g., list branches:

git branch

e.g., create a new branch:

git branch -b feature-login

What it does:

  • Lists existing branches

  • Creates new branches

7. 'git checkout' - Switch Branches

This command switches between branches or restores files.

git checkout feature-login

What it does:

  • Changes your working directory to another branch

  • Lets you work on different versions of the project

8. 'git merge' - Merge Branches

git merge combines changes from one branch into another.

git merge feature-login

What it does:

  • Merges another branch into the current branch

  • Integrates feature work into main or master

9. 'git remote' - Manage Remote Repositories

This command manages connections to remote repositories like GitHub.

e.g., list remotes:

git remote -v

e.g., add a remote:

git remote add origin https://github.com/username/repo.git

What it does:

  • Links your local repository to remote repositories

  • Enables pushing and pulling code

10. 'git push' - Upload Changes to Remote

git push sends your local commits to a remote repository.

git push origin main

What it does:

  • Uploads commits to GitHub/GitLab/Bitbucket

  • Shares your work with others

Bonus Command: 'git pull' – Get Latest Changes

While not in the main list, this is one of the most-used commands.

git pull origin main

What it does:

  • Fetches and merges updates from a remote repository

  • Keeps your local code up to date

Conclusion

Mastering these 10 basic Git commands gives you a solid foundation for version control. With just these commands, you can:

  • Track changes

  • Save progress

  • Collaborate with teams

  • Manage project history

Once you’re comfortable with these basics, you can explore advanced features like rebasing, stashing, and resolving merge conflicts.

Related Articles