Published on

Some simple git usage

Authors
  • avatar
    Name
    Lif
    Twitter

Add

git add .

Rm

git rm --cache <file>  # rm from git 
git rm --f <file> # rm from disk

Config

git config -l
git config --global http.proxy http://127.0.0.1:8080

Remote

git remote add <your repository>
git remote -v # show remote information
git remote rm <your repository>

Branch

git branch <branchName>  # new a branch
git branch -d <branchName>

Checkout

git checkout <branchName>
git checkout -b <branchName>

Switch

After git v2.23, a new version of checkout comes. The "switch" command provides a simple alternative to "checkout".

git switch <branchName>
git switch -c <branchName>

merge

git checkout main
git merge dev # merge dev to main

rebase

git rebase
gir rebase -i <branchName>

reset

git reset HEAD~<number> # git reset HEAD~2
git reset HEAD^

revert

Used for remote branch.

git revert HEAD~<number> # git revert HEAD~2
git revert HEAD^

cherry-pick

git cherry-pick <HEADNAME>/<branchName>