In this comprehensive git commands cheat sheet you will Learn the essential commands for effective version control and collaboration on GitHub.
Git is an indispensable tool for developers, enabling effective version control, collaboration, and project management. Whether you’re new to Git or looking to refine your skills, this Git Commands Cheat Sheet provides you with a quick reference to the most commonly used commands.
Introduction
In the world of software development, Git is the go-to version control system. It allows multiple people to work on a project simultaneously without conflicts, maintains a history of changes, and facilitates collaboration. This Git Cheat Sheet covers the fundamental commands you need to navigate Git like a pro.
Git Basics
What is Git?
Git is a distributed version control system that helps manage and track changes in your code. It’s used by developers worldwide for its efficiency and reliability.
Why Use a Git Cheat Sheet?
A Git Bash Command Cheat Sheet serves as a handy reference, especially when you’re in the middle of a coding session and need a quick reminder of a command.
Pandas Cheat Sheet: https://deepnexus.blogspot.com/2024/07/pandas-cheat-sheet-essential-guide-for.html
Python Cheat Sheet: https://deepnexus.blogspot.com/2024/07/python-cheatsheet-python-basics-cheat.html
Essential Git Commands
git init
Initialize a new Git repository in your current directory.
git init
git clone
Clone an existing repository from GitHub or another remote location.
git clone <repository_url>
git status
Check the status of your working directory and staging area.
git status
git add
Add changes in the working directory to the staging area.y code
git add <file_name>
Add all changes:
git add .
git commit
Commit the staged changes to the repository with a descriptive message.
git commit -m "Your commit message"
git push
Push your changes to a remote repository, such as GitHub.
git push origin <branch_name>
git pull
Fetch and merge changes from a remote repository to your local repository.
git pull
git fetch
Retrieve the latest changes from a remote repository without merging.
git fetch
git branch
List all branches or create a new branch.
git branch
Create a new branch:
git branch <new_branch_name>
git checkout
Switch to a different branch or restore working tree files.
git checkout <branch_name>
Create and switch to a new branch:
git checkout -b <new_branch_name>
git merge
Merge changes from one branch into your current branch.
git merge <branch_name>
git log
View the commit history.
git log
git diff
Show changes between commits, branches, or your working directory and the staging area.
git diff
git reset
Undo changes by resetting the staging area and/or the working directory.
git reset <file_name>
Soft reset:
git reset --soft <commit_hash>
Hard reset:
git reset --hard <commit_hash>
git rm
Remove files from the working directory and the staging area.
git rm <file_name>
git stash
Stash changes in a dirty working directory to clean up your working directory.
git stash
git stash pop
Apply the most recently stashed changes and remove them from the stash list.
git stash pop
git remote
Manage remote repository connections.
git remote -v
Add a remote repository:
git remote add origin <repository_url>
git tag
Create, list, delete, or verify tags.
git tag
Create a new tag:
git tag -a v1.0 -m "Version 1.0"
git show
Show various types of objects (e.g., commits, tags).
git show <object>
git rebase
Reapply commits on top of another base tip.
git rebase <branch_name>
Downloading the Git Commands Cheat Sheet PDF
For your convenience, you can download the complete Git cheat sheet in PDF format from the following link:
FAQs
What is the difference between git fetch and git pull? Git fetch retrieves the latest changes from the remote repository but does not merge them into your working directory, while git pull does both.
How can I undo a commit? You can use git reset to undo a commit. Use — soft to keep changes staged or — hard to discard changes.
What is a detached HEAD in Git? A detached HEAD means you are not on any branch but instead working directly on a commit.
How do I resolve merge conflicts in Git? To resolve merge conflicts, manually edit the conflicting files, then add and commit the resolved changes.
Can I delete a Git branch? Yes, you can delete a branch using git branch -d <branch_name> if it has been merged, or git branch -D <branch_name> to force deletion.
How do I rename a branch in Git? You can rename the current branch using git branch -m <new_branch_name>.
0 Comments