Git Commands: The Complete Guide for Beginners (2026)

Quick Answer: Git is the world’s most popular version-control system. The commands you’ll use most are git clone, git add, git commit, git push, git pull, and git branch. This complete guide walks through every essential Git command โ€” from your first commit to branching, remotes, and undoing mistakes โ€” with links to in-depth tutorials for each.

What Is Git?

Git is a free, open-source distributed version control system that tracks changes to your code, lets multiple people collaborate, and makes it easy to branch, merge, and roll back. It’s a foundational skill for every developer and DevOps engineer.

Git Setup & Configuration

git --version                          # check Git is installed
git config --global user.name "You"    # set your name
git config --global user.email "you@example.com"
git config --list                      # view configuration

Starting a Repository

git init                 # create a new repo in the current folder
git clone <url>           # copy a remote repo locally
git status               # see what's changed

The Core Workflow (Add, Commit, Push)

git add .                # stage all changes
git add file.txt         # stage a specific file
git commit -m "message"  # commit staged changes
git push                 # upload commits to the remote
git pull                 # fetch and merge remote changes

Branching & Merging

git branch                 # list local branches
git branch feature         # create a branch
git checkout feature       # switch to a branch
git switch -c feature      # create and switch (modern syntax)
git merge feature          # merge a branch into the current one

๐Ÿ“˜ Deep dives: How to Delete a Git Branch (Locally & Remotely) ยท How to List Remote Branches in Git.

Working with Remotes

git remote -v                    # list remotes
git remote add origin <url>       # add a remote
git fetch origin                 # download remote changes (no merge)
git branch -r                    # list remote branches

Undoing Changes & Mistakes

git restore file.txt       # discard local changes to a file
git reset --soft HEAD~1    # undo last commit, keep changes staged
git reset --hard HEAD~1    # undo last commit AND discard changes
git revert <commit>         # safely undo a pushed commit

๐Ÿ“˜ Deep dive: How to Undo the Most Recent Local Commits in Git.

Git Commands Cheat Sheet

CommandDescription
git initInitialize a new repository
git clone <url>Clone a remote repository
git statusShow working-tree status
git addStage changes
git commit -mCommit staged changes
git push / git pullUpload / download commits
git branchList or create branches
git mergeMerge branches
git logView commit history
git revert / git resetUndo commits

Using Git in DevOps pipelines? See our Jenkins CI/CD tutorial and the DevOps Roadmap.

Frequently Asked Questions

What are the most important Git commands?

clone, add, commit, push, pull, branch, checkout/switch, merge, and status cover the vast majority of day-to-day Git work.

What is the difference between git reset and git revert?

git reset moves the branch pointer back (rewriting history); git revert creates a new commit that undoes a change, which is safer for shared branches.

How do I undo my last commit?

Use git reset --soft HEAD~1 to undo the commit but keep your changes, or git reset --hard HEAD~1 to discard them entirely.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *