Panel For Example Panel For Example Panel For Example

Common Git Commands Explained

Author : Adrian January 06, 2026

Overview

Learn these Git commands, since you will use them for about 99% of your time with Git.

 

Essential Commands

  1. git init
    Initialize a new Git repository. This creates a ".git" subdirectory in the current directory where Git stores all repository metadata.
  2. git clone
    Clone an existing repository. This creates a local copy of the repository including its history and branches.
    Example: git clone <repository-url>
  3. git add
    Add changes to the next commit. This stages the specified files so they will be included in the next commit.
    Example: git add file1.txt file2.txt
  4. git commit
    Create a new commit. This records the staged changes and any other changes since the last commit, along with a commit message describing the changes.
    Example: git commit -m "Add new feature"
  5. git push
    Push commits to a remote repository. This sends local commits to the specified remote and updates the remote branch to include the new commits.
    Example: git push origin main
  6. git pull
    Fetch and merge changes from a remote repository. This retrieves the latest commits from the specified remote and merges them into the current branch.
    Example: git pull origin main
  7. git branch
    List, create, or delete branches. Use this command to view available branches, create a new branch, or remove an existing one.
    Example: git branch new-branch
  8. git checkout
    Switch to a different branch. This command lets you change the current working branch.
    Example: git checkout main
  9. git merge
    Merge one branch into another. This applies the changes from one branch into another and creates a commit that reflects the merge.
    Example: git merge new-branch
  10. git status
    Show the repository status. This displays the current branch, any staged or unstaged changes, and any untracked files.
    Example: git status
  11. git rebase
    Reapply commits on top of another base tip. For example, if you made changes on branch "XYZ" and want to apply them onto "main", use git rebase to replay those commits on top of main.
  12. git stash
    Temporarily save changes that are not ready to commit. If your changes are not ready but you need to switch branches, use git stash to save the work for later without losing progress.
  13. git revert
    Create a new commit that undoes the changes introduced by a previous commit. Use this to safely undo changes that were already committed.
    Example: git revert <commit1>..<commit2>

 

Command Explanations

git init initializes a new repository by creating a ".git" directory in the current folder, which holds all repository metadata.

git clone copies an existing repository to your local machine, including all history and branches.

git add stages modified files for the next commit. You can specify which files to stage, for example: git add file1.txt file2.txt.

git commit records the staged changes and other modifications since the last commit, accompanied by a commit message, for example: git commit -m "Add new feature".

git push sends local commits to a remote repository and updates the remote branch, for example: git push origin main.

git pull fetches and merges commits from a remote repository into the current branch, for example: git pull origin main.

git branch lists, creates, or deletes branches. Use it to view available branches or create a new one, for example: git branch new-branch.

git checkout switches the working branch, for example: git checkout main.

git merge integrates changes from one branch into another, creating a merge commit that reflects the combined history, for example: git merge new-branch.

git status shows the current branch, staged and unstaged changes, and untracked files, for example: git status.

git rebase reapplies commits from one branch onto another base, which can produce a linear history when used appropriately.

git stash temporarily stores changes that are not ready to commit, allowing you to switch branches and later reapply the stashed changes.

git revert creates a new commit that reverses the effects of a previous commit, which is useful for undoing changes that have already been published.

 

Summary

These are the most commonly used Git commands. Mastering them will significantly improve your development efficiency.