Git Cheat Sheet

Enthusiast Cloud and Security with expertise in AWS and DevOps. Proficient in Python, Bash, Git, Jenkins, and container orchestration tools like Docker and Kubernetes, I focus on automation and CI/CD practices. I leverage security tools such as NMAP, Nessus, and Metasploit to identify and mitigate vulnerabilities. Passionate about learning and collaboration, I thrive on enhancing cloud security and efficiency. Always eager to advance my skills, I aim to contribute to the tech community.
What is Git?
Git is a distributed version control system designed to track changes in source code during software development. It allows multiple developers to work on a project simultaneously, managing code versions, collaboration, and backup. Git is essential for managing different versions of projects, making it easy to revert back to previous versions or create branches to develop new features without affecting the main codebase.
Git Cheat Sheet
1. Basic Commands
| Command | Description |
git init | Initialize a new Git repository in your project folder. |
git clone <url> | Clone a repository from a remote server. |
git status | Show the current status of your repository (modified, staged, or untracked files). |
git add <file> | Add a specific file to the staging area. |
git add . | Add all files (tracked and untracked) to the staging area. |
git commit -m "message" | Commit the staged changes with a message. |
git commit -am "message" | Commit changes with a message (tracked files only). |
git log | View the commit history. |
git diff | Show the changes in the working directory that haven’t been staged yet. |
git diff --staged | Show the changes between the staged files and the last commit. |
git reset <file> | Unstage a file from the staging area. |
git reset --hard | Reset the working directory and staging area to the last commit. All changes will be lost. |
2. Branching & Merging
| Command | Description |
git branch | List all branches in the repository. |
git branch <branch-name> | Create a new branch. |
git checkout <branch-name> | Switch to another branch. |
git checkout -b <branch-name> | Create and switch to a new branch. |
git merge <branch-name> | Merge the specified branch into the current branch. |
git branch -d <branch-name> | Delete a branch. |
git stash | Stash changes without committing. |
git stash pop | Apply the stashed changes. |
3. Remote Repositories
| Command | Description |
git remote -v | View the remote repositories linked to your local repository. |
git remote add <name> <url> | Add a new remote repository. |
git fetch <remote> | Fetch the latest changes from the remote repository (without merging). |
git pull <remote> | Fetch and merge changes from the remote repository to your current branch. |
git push <remote> <branch> | Push your changes to the specified remote branch. |
4. Undoing Changes
| Command | Description |
git checkout -- <file> | Discard changes in a working directory (restore file to last commit state). |
git reset HEAD~1 | Undo the last commit but keep changes in the working directory. |
git revert <commit> | Revert a specific commit by creating a new commit. |
5. Tagging
| Command | Description |
git tag | List all tags in the repository. |
git tag <tag-name> | Create a new tag. |
git tag -d <tag-name> | Delete a tag. |
git push <remote> --tags | Push tags to the remote repository. |
6. Viewing Commits
| Command | Description |
git show <commit> | Show details of a specific commit. |
git log --oneline | View the commit history in a simplified format. |
git log --graph --decorate --all | View a graphical representation of the commit history. |
This cheat sheet should cover most of the essential commands you'll use regularly with Git!
Thanks,
Nihal Shardul.




