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: <span style="font-size: 10.0pt;">ssh -T
git@github.com</span>
o Initialize
a new Git repository: <span style="font-size: 10.0pt;">git init</span>
o Clone
an existing repository: <span style="font-size: 10.0pt;">git clone
<repo-url></span>
2.
Staging and Committing Changes
o Add
files to the staging area: <span style="font-size: 10.0pt;">git add
<file name></span>
o Commit
changes with a descriptive message: <span style="font-size: 10.0pt;">git
commit -m "Commit message"</span>
o View
the commit history: <span style="font-size: 10.0pt;">git log</span>
o View
the last 5 commits: <span style="font-size: 10.0pt;">git log -n 5</span>
o View
commits in a concise format: <span style="font-size: 10.0pt;">git log
--oneline</span>
3.
Branching and Merging
o List
all branches: <span style="font-size: 10.0pt;">git branch --list</span>
o Create
and switch to a new branch: <span style="font-size: 10.0pt;">git checkout
-b <branch-name></span>
o Switch
to an existing branch: <span style="font-size: 10.0pt;">git checkout
<branch-name></span>
o Merge
a branch into the current branch: <span style="font-size: 10.0pt;">git
merge <branch-name></span>
o Abort
a merge in case of conflicts: <span style="font-size: 10.0pt;">git merge
--abort</span>
o Continue
a merge after resolving conflicts: <span style="font-size: 10.0pt;">git
merge --continue</span>
4.
Remote Repositories
o Add
a remote repository: <span style="font-size: 10.0pt;">git remote add origin
<Url to repo></span>
o Fetch
changes from the remote repository: <span style="font-size: 10.0pt;">git
fetch origin</span>
o Pull
the latest changes from the remote repository: <span style="font-size: 10.0pt;">git pull</span>
o Push
changes to the remote repository: <span style="font-size: 10.0pt;">git push
-u origin master</span>
o Delete
a remote branch: <span style="font-size: 10.0pt;">git push origin --delete
<branch-name></span>
5.
Stashing Changes
o Stash
current changes: <span style="font-size: 10.0pt;">git stash</span>
o List
all stashes: <span style="font-size: 10.0pt;">git stash list</span>
o Apply
the latest stash: <span style="font-size: 10.0pt;">git stash apply</span>
o Apply
and delete the latest stash: <span style="font-size: 10.0pt;">git stash pop</span>
o Delete
all stashes: <span style="font-size: 10.0pt;">git stash clear</span>
6.
Submodules
o Add
a submodule: <span style="font-size: 10.0pt;">git submodule add <url>
<path></span>
o Initialize
submodules: <span style="font-size: 10.0pt;">git submodule init</span>
o Update
submodules: <span style="font-size: 10.0pt;">git submodule update</span>
o Pull
the latest changes for all submodules: <span style="font-size: 10.0pt;">git
submodule foreach git pull origin master</span>
7.
Tags
o Create
a tag: <span style="font-size: 10.0pt;">git tag <tag name></span>
o List
all tags: <span style="font-size: 10.0pt;">git tag -l</span>
o Delete
a local tag: <span style="font-size: 10.0pt;">git tag -d <tag name></span>
o Delete
a remote tag: <span style="font-size: 10.0pt;">git push --delete origin
<tag name></span>
o Push
all tags to the remote repository: <span style="font-size: 10.0pt;">git
push origin --tags</span>
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!