DEV Community

Cover image for Complete Git Cheat sheet

Complete Git Cheat sheet

Navigating the complexities of version control can be a daunting task, so understanding Git is essential for efficient and collaborative software development. Git enables you to effectively manage code and collaborate seamlessly with other developers as well as many other functions.
This Git cheat sheet is designed to be your quick reference guide, offering a concise reference for the essential commands and concepts in Git.

This is not an introductory article. You must have at least a basic knowledge of Git and GitHub before proceeding to avoid confusion.

If you happen to not be in the above category, visit my previous article, introduction to Git and GItHub, and this YouTube playlist: Git and GitHub tutorial for beginners to get started.

Git commands

Here are the most frequently used Git commands:

●Set Username:
git config __global user.name <desired username>

●Set email:
git config __global user.email <desired email>

●Go back a directory:
cd ..

●List folder content:
Ls

OR
Dir

●Create a new directory:
mkdir <directory name>

●Create a new file inside a directory:
touch <file name>

●Open a file in text editor:
texteditorname <file name>

●Delete a file:
rm <file name>

●Delete a directory:
rmdir <directory name>

●Create a repository:
Step 1:
cd <folder's full path>

Step 2:
git init

●Stage a file:
git add <file name>

●Stage all files:
git add .

●Check changed files/ files in or out of staging area:
git status

●Remove a file from staging area:
git rm __cached <file name>

●Create a commit:
git commit -m "<descriptive commit message>"

●Check commit history:
git log

For a condensed version:
git log __oneline

●Check code of an earlier commit:
git checkout <commit's ID>

●Undo a commit:
git revert <commit's ID>

●Permanently go back to a commit:
git reset <commit's ID>

Note- the code remains in our text editor just in case, so to remove them:
git reset __hard

●Create a branch:
git branch <branch name>

●Go to a branch:
git checkout <branch name>

●Create and go the branch simultaneously:
git checkout -b

●Delete a branch:
git branch -D

for merged branches:
git branch -d

●Merge a branch:
git merge <branch name>

●Remove merged branch conflict:
:wq

●Push Git files to Github:
git push <github repository URL/ github repository URL alias> <branch name>

●Give a Github repository an alias:
git remote add <alias> <github repository URL>

●Clone a Github repository into your computer:
Step 1:
cd ..

Step 2:
git clone <github repository URL>

●Check your github repository URL:
git remote -v

●Make local repository up to date with remote repository:
git pull <github repository URL/ alias> <branch name>

Top comments (3)

Collapse
 
alfred_okelue_d719a919a2c profile image
Alfred Okelue

Great work

Collapse
 
elaine-ui profile image
Ugochinyere Elaine Iheanacho

Thanks!

Collapse
 
orji_chidinma_e56339a2ff3 profile image
Orji Chidinma

Nice one 🙌🏽