Git Cheat Sheet
Shabina Tarique
AWS Certified | Kubernetes, Docker, Jenkins Expert | PCI DSS Compliance Specialist
Introduction: Git is a powerful version control system widely used by developers to manage their projects' source code efficiently. However, navigating through its vast array of commands can be daunting, especially for beginners. To alleviate this challenge, we've compiled a concise yet comprehensive Git Cheat Sheet containing 50 essential commands. This Cheat Sheet covers everything from setting up Git, initializing projects, making changes, understanding core concepts, working with branches, merging, rebasing, undoing actions, reviewing repositories, stashing changes, to synchronizing local and remote repositories. Whether you're a seasoned developer or just starting your journey in programming, this Cheat Sheet serves as an invaluable quick reference to streamline your Git workflow and boost productivity.
?
Setup
Set user name and email for commits and tags
$ git config --global user.name "Your Name" $ git config --global user.email "your_email@example.com"
Starting a Project with Git
Initialize a local repository
$ git init <directory>
Clone a remote repository
$ git clone <url>
Making a Change
Add file(s) to staging
$ git add <file>
Commit staged changes
$ git commit -m "commit message"
Basic Git Concepts
- main: default development branch
- origin: default upstream repository
- HEAD: current branch
- HEAD^: parent of HEAD
- HEAD~4: great-great grandparent of HEAD
Branches
List local branches
$ git branch
Create a new branch
$ git branch <new-branch>
Merging
Merge branch 'a' into 'b'
$ git checkout b $ git merge a
Rebasing
领英推è
?
Rebase feature branch onto main
$ git checkout feature $ git rebase main
Undoing Things
Move/rename a file & stage move
$ git mv <existing_path> <new_path>
Remove file from working directory & staging area
$ git rm <file>
Reviewing Your Repository
Check status of working directory
$ git status
View commit history
$ git log --oneline
Stashing
Store modified & staged changes
$ git stash
Apply stashed changes
$ git stash apply
Synchronizing
Add a remote repository
$ git remote add <alias> <url>
Fetch all branches from remote repository
?
$ git fetch <alias>
Upload local content to remote repository
$ git push <alias>
This cheat sheet provides 50 commonly used Git commands across various topics. It's designed to be a quick reference for setting up Git, starting projects, making changes, understanding basic concepts, working with branches, merging, rebasing, undoing changes, reviewing repositories, stashing, and synchronizing local and remote repositories.
Feel free to use and share this cheat sheet for your reference!
?