Skip to content

Latest commit

 

History

History
122 lines (84 loc) · 1.75 KB

git-cheat-sheet.md

File metadata and controls

122 lines (84 loc) · 1.75 KB

Git Cheet Sheet

Install Git

Github Desktop

Configure User

$ git config [--global] user.name ["YOUR_NAME"]
$ git config [--global] user.email ["YOUR_EMAIL"]

Create Repositories

$ git init
$ git clone URL [LOCAL_REPO_NAME]

Make Changes

$ git status
$ git diff
$ git add [FILE_NAME]
$ git commit -m "COMMIT MESSAGE"

Group Changes

$ git branch
$ git branch [BRANCH_NAME]
$ git checkout [-b] [BRANCH_NAME]
$ git merge [BRANCH_NAME]
$ git branch -d [BRANCH_NAME] # delete local branch

Undoing things

Commit again

$ git commit -m 'initial commit'
$ git add <forgotten-file>
$ git commit --amend

Unstage a staged file

$ git reset HEAD <file>

Unmodify a modified file

NOTE - This command could be dangerous.

$ git checkout -- <file>

Synchronize Changes

$ git fetch [BOOKMARK]
$ git merge [BOOKMARK]/[BRANCH]
$ git push [ALIAS] [BRANCH]
$ git pull

Remote branch

Show remote branches

$ git branch -r
# or
$ git remote show origin

Push local branch to remote branch

$ git push origin [REMOTE_BRANCH_NAME]

Pull from remote branch

$ git checkout [REMOTE_BRANCH_NAME]
# or
$ git checkout -b [LOCAL_BRANCH_NAME] origin/[REMOTE_BRANCH_NAME]
# or
$ git checkout -t origin/[REMOTE_BRANCH_NAME]

Delete remote branch

$ git push origin :[REMOTE_BRANCH_NAME]

Reset the resets

$ git reflog
$ git reset --hare HEAH@{1}

Refer to

Git Cheat Sheet - Official Git-scm Book Learn Git Branching