Git Cheatsheet

Initialise Git

git init

Checkout

git checkout <branch-name>

Create Branch

git checkout -b <branch-name>
git push origin <branch-name> --set-upstream

List all branches

git branch --list

Fetching from remote

git fetch origin
git checkout --track <origin/branch-name>

List merged branches

git branch -a --merged

Delete remote branch

git push origin --delete <branch-name>

Delete local branch

git branch -d <branch-name>

View Changes

git status

Add Files To Git

git add <file name>

Commit Changes

git commit -m "Commit message"

Push Changes

git push -u origin master

Pull Latest Changes

git pull

Undo Changes

Reset current changes

git reset --hard

Undo commit

git reset --hard <commit-id>

Remote origin

git remote add origin <Url to repo>

Tags

List tags

git tag -l

Delete a local tag

git tag -d <tag name>

Delete remoate tag

git push --delete origin <tag name>

Log

Logs in Current Branch

git log

Logs last n number of commits

git log -n 5

Commits between branch1 and branch2

git log branch1..branch2

Commits in branch1 that are not in branch2

git log branch1 ^branch2

Commits for certain file

git log -p filename

Search for commit

git log --oneline | grep "Text to search"

Pretty Logs

git log --oneline --decorate --graph