Skip to content

Techeons

Imagine | Explore | Innovate

Menu
  • Home
Menu

Cheat Sheet: Essential Git Commands

Posted on November 5, 2025

Git is a version control system that helps you track changes in code or files over time. Here’s a brief overview:

Key Concepts:

  1. Repository (Repo): Central location for your project’s files and history.
  2. Commits: Snapshots of changes made to your files.
  3. Branches: Independent lines of development (e.g., feature, fix, or experimental branches).
  4. Remote: A shared repository on a server (e.g., GitHub, GitLab).

Git helps you:

  • Track changes and collaborate with others.
  • Manage different versions of your code.
  • Experiment with new features without affecting the main codebase.

Basic Commands

  1. git init – Initialize a new Git repository.
  2. git clone <repo-url> – Clone a repository from a URL.
  3. git add <file> – Stage a file for the next commit.
  4. git add . – Stage all changes in the current directory.
  5. git commit -m "<message>" – Commit changes with a meaningful message.
  6. git log – Display a log of all commits.
  7. git status – Show the status of the repository.

Branching

  1. git branch <branch-name> : Create a new branch.
  2. git checkout <branch-name> : Switch to a different branch.
  3. git checkout -b <branch-name> : Create and switch to a new branch.
  4. git branch -d <branch-name> : Delete a branch.
  5. git branch -D <branch-name> : Force delete a branch.

Remote Commands

  1. git remote add <name> <url> : Add a remote repository.
  2. git fetch <remote-name> : Fetch changes from a remote repository.
  3. git push <remote-name> <branch-name> : Push changes to a remote repository.
  4. git pull <remote-name> <branch-name> : Fetch and merge changes from a remote repository.
  5. git remote -v : Display remote repository URLs.
  6. git remote set-url origin <new-url> : Update the remote Git repository URL

Undo and Reset

  1. git reset <file> : Unstage a file.
  2. git reset --hard : Discard all changes and reset to the last commit.
  3. git revert <commit-hash> : Revert a specific commit.
  4. git checkout -- <file> : Discard changes in a file.

Miscellaneous

  1. git diff – Show changes between the working directory and the index.
  2. git diff --cached – Show changes between the index and the last commit.
  3. git tag <tag-name> – Create a new tag.
Share on Social Media
x facebook pinterest linkedin tumblr reddit emailwhatsapptelegrammastodon

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Nginx: How to increase timeout for Nginx
  • Cheat Sheet: Essential Git Commands
  • Setting a default shell in Linux
  • Setting up Composer on Linux
  • Switch easily between Python versions on a Mac using pyenv

Tags

ai alerting aws b2 backblaze certificate cheatsheet cloud commands data-science datalake devops dns docker dremio git gitlab infra jenkins kubernetes linux metabase minikube minio monitoring mount mysql nginx nodejs notebooks openssh php python scala secrets spark ssh ssl ubuntu ufw usb web dev tools windows xampp zeppelin

©2026 Techeons | Design: Newspaperly WordPress Theme