Skip to main content
Ganesh Joshi
Back to Cheatsheets

Git commands

Updated 2026-02-08

Frequently used Git commands and options for daily workflow.

Basics

  • git init

    Init repo.

  • git clone <url>

    Clone a repository.

  • git status

    Working tree status.

  • git add <path>

    Stage file(s).

  • git add .

    Stage all changes.

  • git commit -m "msg"

    Commit with message.

Branching

  • git branch

    List branches.

  • git branch <name>

    Create branch.

  • git checkout <name>

    Switch branch.

  • git switch <name>

    Switch branch (newer).

  • git checkout -b <name>

    Create and switch.

  • git merge <branch>

    Merge into current branch.

Remote

  • git remote -v

    List remotes.

  • git fetch origin

    Fetch from remote.

  • git pull

    Fetch and merge.

  • git push origin <branch>

    Push to remote.

  • git push -u origin <branch>

    Push and set upstream.

Undo / history

  • git log --oneline

    Short log.

  • git diff

    Unstaged changes.

  • git restore <file>

    Discard changes in file.

  • git reset --soft HEAD~1

    Undo last commit, keep changes staged.

Git commands | Cheatsheet | Ganesh Joshi