Currently Empty: 0.00 €
Git Version Control Cheat Sheet
This cheat sheet serves as a quick reference for developers and IT professionals, enabling efficient and effective Git version control management.
Git Version Control Commands
This cheat sheet provides a comprehensive collection of essential Git commands for managing and collaborating on code repositories. It covers a wide range of tools and techniques used for initializing repositories, managing branches, committing changes, handling remote repositories, and performing advanced tasks like rebasing and stashing. Whether you’re tracking changes, merging branches, resolving conflicts, or maintaining a clean commit history, these commands will help streamline your version control process and enhance your software development workflow.
![Git Version Control](https://route2open.com/wp-content/uploads/2024/07/Robot_R2O_Git-1347x1536.webp)
Setup and Config
Creating Repositories
- git config --global user.name "mail"
- git config --global user.email "mail"
- git config --list
Set user name
Set user email
List all config settings
- git init
- git clone <repository-url>
Initialize a new Git repository
Clone an existing repository
Basic Snapshotting
Branching and Merging
- git add <file/directory>
- git add .
- git commit -m "Commit message"
- git commit -am "Commit message"
- git log
- git log --oneline
Add files to the staging area
Add all files to the staging area
Commit changes
Commit all changes (skipping the staging area)
View commit history
View commit history with one line per commit
- git branch
- git branch <branch-name>
- git checkout <branch-name>
- git checkout -b <branch-name>
- git merge <branch-name>
- git branch -d <branch-name>
List all branches
Create a new branch
Switch to a branch
Create and switch to a new branch
Merge a branch into the current branch
Delete a branch
Remote Repositories
Viewing and Comparing
- git status
- git diff <commit-id-1> <commit-id-2>
- git diff
- git diff --staged
Show changes in the working directory
Show changes between commits
Show changes between working directory and last commit
Show changes in the staging area
- git stash
- git stash list
- git stash apply
- git stash pop
- git stash drop <stash@{n}>
- git stash clear
List all branches
Create a new branch
Switch to a branch
Create and switch to a new branch
Merge a branch into the current branch
Delete a branch
Rewriting History
Resetting and Reverting
- git commit --amend
- git rebase <branch-name>
- git rebase --abort
- git rebase --continue
- git rebase -i <commit-id>
Amend the last commit
Rebase the current branch onto another branch
Abort a rebase
Continue a rebase after resolving conflicts
Interactively rebase
-
git reset
-
git reset --soft
-
git reset --hard
-
git revert
Unstage a file
Reset the staging area but keep the working directory
Reset the staging area and the working directory
Revert a commit
Tagging
Ignoring Files
- git tag
- git tag <tag-name>
- git tag -a <tag-name> -m "Tag message"
- git push <remote-name> <tag-name>
- git tag -d <tag-name>
- git push <remote-name> :refs/tags/<tag-name>
List all tags
Create a new tag
Create an annotated tag
Push a tag to a remote repository
Delete a local tag
Delete a remote tag
- echo <file-pattern> >> .gitignore
- git status --ignored
Add a file or pattern to .gitignore
Show ignored files
Cleaning Up
Submodules
- git clean -fd
- git clean -f
- git clean -fd
- git push <remote-name> <tag-name>
- git tag -d <tag-name>
- git push <remote-name> :refs/tags/<tag-name>
List all tags
Create a new tag
Create an annotated tag
Push a tag to a remote repository
Delete a local tag
Delete a remote tag
- git submodule add <repository-url> <path>
- git submodule init
- git submodule update
- git clone --recurse-submodules <repository-url>
Add a submodule
Initialize submodules
Update submodules
Clone a repository and initialize submodules
Alias
- git config --global alias.<alias-name> '<git-command>'
- git config --global alias.st 'status'
Create an alias
Example: Create a short alias for ‘git status’
![](https://route2open.com/wp-content/uploads/2024/07/Git_logo-300x300.webp)
What is Git?
Git is a powerful distributed version control system designed to help developers track changes in their code, collaborate with others, and manage projects efficiently. Created by Linus Torvalds in 2005, Git has become the standard for version control in the software development industry. It provides robust tools for managing project history, branching and merging code, and working
with remote repositories.
with remote repositories.
Git Tips
- Descriptive Commits: git commit -m “Fix login issue”
- Branch for Features: git checkout -b feature/new-feature
- Stash Changes: git stash
- Rebase for Clean History: git rebase main.
- Use Aliases: git config –global alias.co checkout
- .gitignore: echo “node_modules/” >> .gitignore
- Check Status: git status
- View Logs: git log –oneline –graph –all
- Review Changes: git diff
- Pull with Rebase: git pull –rebase origin main
GNS3 Knowledge Base
Discover a wealth of information and expert tips in our GNS3 Knowledge Base, your go-to resource for mastering network simulations. Whether you need detailed tutorials, expert tips, or troubleshooting advice, our Knowledge Base has everything to enhance your skills and solve any challenges. Dive in now to enhance your skills and troubleshoot any challenges with ease!
![](https://route2open.com/wp-content/uploads/2024/05/slider_img-1.png)
Share the Knowledge: Spread the Word About Our Git Cheat Sheet!
If you find this page helpful for your networking knowledge and skills, please consider sharing it with your friends, colleagues, and social media followers. Your support helps us create more valuable resources and enhance our courses.
You can share this page on your social media accounts like Facebook, LinkedIn, Twitter, and any related networking and programming forums or blogs. By sharing, you assist other networking enthusiasts in their learning journey, making their work easier and more efficient. So, if you’d like to help others, kindly share this page.
For more in-depth networking knowledge, visit our route2open courses.