Skip to content
Go back

Git Commands

Updated:
Edit Page

Git

Rebase with another repo

git remote add repo https://github.com/repo
git fetch repo
git rebase repo/main
git remote remove repo

Redo last commit git reset --soft HEAD~1

Merge one file from another branch git checkout --patch otherbranch file If new file, use it without --patch

Fix up a previous commit.

git commit --fixup <commit>
git rebase --auto-squash <commit>~1

Rebase from certain commit. Extremely useful when your team squashes the commits and you have to rebase onto the latest branch.

git rebase --onto <branch> <commit>

Checkout a file from other branch

git restore --source <branch> -W <filepath>

Aliases

Shell alias

gpsup='git push --set-upstream origin $(git_current_branch)'
gaa='git add --all'
gau='git add --update'

Git config

[alias]
    co = checkout
    br = branch
    ca = commit --amend
    cm = commit -m
    ls = log --all --decorate --oneline --graph
    pf = push --force-with-lease
[pull]
    ff = only
[core]
    editor = vim

Commit message

I seldomly follow it but this is the first convention I’ve learned.

http://karma-runner.github.io/6.3/dev/git-commit-msg.html


Edit Page
Share this post on:

Next Post
Bloodborne - A Masterpiece(zh)