Skip to content

git

git config

shell
git config --global  user.name "tangzixuan"           
git config --global user.email "[email protected]"         
git config --global pull.rebase true       
ssh-keygen -t rsa -C "[email protected]"         
pbcopy < ~/.ssh/id_rsa.pub   or  cat ~/.ssh/id_rsa.pub   //to get public key        
git config --global pull.rebase true // 非常有用的

basic command

shell
git add .      
git commit -m "feat: commit message"              
git push / git push -f     
git pull origin master  // 在sub branch,合并远程主干分支         
git stash                
git stash apply                        
git checkout main       
git rebase dev        
git cherry-pick  
git reset --hard
git reset --soft
git revert commitId
git revert HEAD^
git submodule add https://github.com/tangzixuan/develop-template   // git submodule使用:父目录添加子目录
git mv develop-template my-project/develop-template   // 移动 gitsubmodule 目录, https://stackoverflow.com/questions/4604486/how-do-i-move-an-existing-git-submodule-within-a-git-repository
git submodule update --init --recursive  // git submodule初始化:子目录初始化
git submodule sync  // 修改子模块地址时用到
# create tag
git tag -a 1.4 -m "my version 1.4"
# push all tag to remote
git push origin 1.0  // https://stackoverflow.com/questions/5195859/how-do-you-push-a-tag-to-a-remote-repository-using-git
git push origin --tags
# 分支检出:巨型仓库检出
git sparse checkout
git merge --abort # The unresolved conflict will be cleared off
git branch | grep -v "master" | xargs git branch -D # delete local branch except master: <https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/delete-all-branches-except-master-main-local-remote>

经典notes