GIT Commands

Some useful GIT commands.

Git config

git config --global user.name "Your name"
git config --global user.email you@example.com

Omit –global for use on individual projects.

Create new repository

git init

Clone

git clone /path/to/repository

Remote

git clone username@host:/path/to/repository

Branch

New and switch

git checkout -b 

Switch branch

git checkout 

List branches

git branch

Delete branch

git branch -d 

Push branch

git push origin 

Update repository

git pull

Merge branch

git merge 

View all the merge conflicts

git diff

File conflicts

git diff --base 

Preview changes

git diff  

Undo changes

git checkout -- 

Drop changes

git fetch origin
git reset --hard origin/master

Status

git status

Add

git add 
git add *

Commit

git commit -m "Commit message"

Push

git push origin master

Stash Changes

git stash

Restore stashed changes

git stash pop

Search

git grep "foo()"

https://dzone.com/articles/top-20-git-commands-with-examples

Useful GIT resources

A useful explanation of git in simple terms.
https://dev.to/sublimegeek/git-staging-area-explained-like-im-five-1anh

Git rebase
https://dev.to/maxwell_dev/the-git-rebase-introduction-i-wish-id-had

Git merge vs rebase
https://dev.to/neshaz/git-merge-vs-git-rebase-5134

Git stash
https://dev.to/srebalaji/useful-tricks-you-might-not-know-about-git-stash-117e

Git branching
https://dev.to/thadevelyouknow/git-branching-step-by-step-2pcc

Cheatsheet
https://dev.to/t4rzsan/next-step-git-for-those-that-already-know-add-and-commit-55ac