DEV Community

Cover image for Git cheat sheet
Mahmoud EL-kariouny
Mahmoud EL-kariouny

Posted on

Git cheat sheet

Git configuration

git config --global user.name "Your Name"
git config --global user.email "Your Email"
Enter fullscreen mode Exit fullscreen mode

Starting a project

git init [project name]
git clone [project url]
Enter fullscreen mode Exit fullscreen mode

Remove file from directory

git rm [file name]
Enter fullscreen mode Exit fullscreen mode

Status of working directory

git status 
Enter fullscreen mode Exit fullscreen mode

Add a file to the staging area

git add [file name]
Enter fullscreen mode Exit fullscreen mode

Discard changes in working directory

git checkout --[file name]
Enter fullscreen mode Exit fullscreen mode

Commit to local

git commit
Enter fullscreen mode Exit fullscreen mode

Revert your repository

git reset [file name]
Enter fullscreen mode Exit fullscreen mode

List all local branches

git branch [-a]
Enter fullscreen mode Exit fullscreen mode

Fetch changes from the remote and merge current branch with its upstream

git pull [remote]
Enter fullscreen mode Exit fullscreen mode

Join specified from name branches

git merge [from name]
Enter fullscreen mode Exit fullscreen mode

Create new branch

git branch [branch name]
Enter fullscreen mode Exit fullscreen mode

Push local changes to the remote

git push [--tags] [remote]
Enter fullscreen mode Exit fullscreen mode

Remove selected branch

git branch -d [branch name]
Enter fullscreen mode Exit fullscreen mode

Fetch changes from the remote

git fetch [remote]
Enter fullscreen mode Exit fullscreen mode

Switch current branch to specified branch

git checkout [-b] [branch name]
Enter fullscreen mode Exit fullscreen mode

Git cheat sheet image

Image description

All the best to you.

Top comments (0)