Git — Robin Wils's website

Last modified: Sat, Oct 22, 2022

Basics

Add

# Add specific file
git add <filepath>/<filename>

# Add all not hidden files
git add *

# Add all hidden files
git add .*

Status

git status

Remove file from staging area

git rm --cached <file>

Make commit

git commit -m "Your commit message"

Remove commit on remote

git reset --hard HEAD~1
git push --force

Push changes

git push

Branches

Rebase

git checkout some-feature
git rebase master

Show branches

git branch -a

Switch to existing branch

# Use tab completion, usually looks like origin/<branch-name>.
git checkout -b <branch-name>

Make new branch with code from master

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

Delete local branch

git branch -d <name>

Delete remote branch

git push --delete origin <name>

Rename branch

git branch -m <old-name> <new-name>
git push --delete origin <old-name>
git branch --unset-upstream
git push --set-upstream origin <new-name>

Merge

# Switch to branch for example master
git checkout -b master

# Pull changes from branch with new changes
git pull origin <my-cool-feature>

# Push it, if merges do commit first
git push

Remote add

git remote add origin https://github.com/user/repo.git

Remote delete

git remote rm origin