- GIT -

Essential Git Commands

Create a New Repository

git init
git add .
git commit -m 'commit message'
git remote add origin git@github.com:username/repo.git
git push -u origin master

Clone a Repository

git clone git@github.com:username/repo.git

Pull changes from Remote Branch

git pull origin <branch>

Push changes from Remote

git push origin <branch>

Working with Local Changes

git status
git add .
git add -p <file>
git commit -m 'commit message'

Viewing History

git log
git log --oneline
git blame <file>

Branch & Merge

git branch
git branch -a
git checkout <branch>
git checkout -b <branch>
git merge <branch>
git merge --no-ff <branch>

Undoing Changes

git reset --hard HEAD
git reset --hard <commit_hash>
git checkout HEAD <file>
git revert <commit_hash>

Temporary Commits

git stash

Save modified and staged changes

git stash list

List all stashes

git stash pop

Write latest stash to working tree

git stash apply

Apply latest stash to working tree

git stash drop

Discard latest stash

View Differences

git diff

View changes between the working tree and the index

git diff <file>

View changes between the working tree and the index or a specific file

git diff HEAD

View changes between the working tree and last commit

Deleting Branches

git branch -d <branch>

Delete a local branch (if merged)

git branch -D <branch>

Force Delete a local branch

git push origin --delete <branch>

Delete a remote branch

Configuration

git config --global user.name 'username'
git config --global user.name '[firstname lastname]'
git config --global user.email 'email'

Tags

  • GIT
  • github
  • gitlab
  • version control