As a developer, having a solid understanding of Git is crucial for efficient version control and collaborative development. This comprehensive cheatsheet will help you navigate through the most essential Git commands, empowering you to streamline your workflow and boost your productivity.
1.
Getting Started
o Test
your GitHub connection: ssh -T
git@github.com
o Initialize
a new Git repository: git init
o Clone
an existing repository: git clone
<repo-url>
2.
Staging and Committing Changes
o Add
files to the staging area: git add
<file name>
o Commit
changes with a descriptive message: git
commit -m "Commit message"
o View
the commit history: git log
o View
the last 5 commits: git log -n 5
o View
commits in a concise format: git log
--oneline
3.
Branching and Merging
o List
all branches: git branch --list
o Create
and switch to a new branch: git checkout
-b <branch-name>
o Switch
to an existing branch: git checkout
<branch-name>
o Merge
a branch into the current branch: git
merge <branch-name>
o Abort
a merge in case of conflicts: git merge
--abort
o Continue
a merge after resolving conflicts: git
merge --continue
4.
Remote Repositories
o Add
a remote repository: git remote add origin
<Url to repo>
o Fetch
changes from the remote repository: git
fetch origin
o Pull
the latest changes from the remote repository: git pull
o Push
changes to the remote repository: git push
-u origin master
o Delete
a remote branch: git push origin --delete
<branch-name>
5.
Stashing Changes
o Stash
current changes: git stash
o List
all stashes: git stash list
o Apply
the latest stash: git stash apply
o Apply
and delete the latest stash: git stash pop
o Delete
all stashes: git stash clear
6.
Submodules
o Add
a submodule: git submodule add <url>
<path>
o Initialize
submodules: git submodule init
o Update
submodules: git submodule update
o Pull
the latest changes for all submodules: git
submodule foreach git pull origin master
7.
Tags
o Create
a tag: git tag <tag name>
o List
all tags: git tag -l
o Delete
a local tag: git tag -d <tag name>
o Delete
a remote tag: git push --delete origin
<tag name>
o Push
all tags to the remote repository: git
push origin --tags
By mastering these Git commands, you'll be well-equipped to efficiently manage your source code, collaborate with others, and streamline your development process. Keep this cheatsheet handy, and you'll be on your way to becoming a Git pro in no time!
Thanks for sharing your feedback! It helps us grow.