1. git clone ssh://git@xxxxxxx/project.git (clone 远程git repo 到当前目录, 自动生成project目录,里面包含所有project资源,cd project即可)
2. git checkout --track origin/feature/xxxx (生成一个本地feature/xxxx 分支,并且对应的远程分支为origin/feature/xxxx)
3. git checkout -b <Branch-name>(生成一个本地Branch-name的分支)
4. git commit -m "MSG" (commit to 本地分支,MSG是commit时带有的message)
5. git remote set-url origin <remote git url>
6. git push -u origin --all (5. 和6.可以一起使用,用来向希望使用的远程git repo推送change)
7. git merge commit commit-number/branch (commit/branch 对应的所有修改都会应用在当前的分支)
8. git clean -df (删除所有non-track的文件和目录)
9. git branch -l (列出所有本地分支)
10. git branch -r (列出所有远程分支)
11. git branch -D <Branch-name> (删除本地 Branch-name分支)
12. git push origin --delete <Branch-name> (删除远程 Branch-name分支)
13. git config --list (当前git repo的status)
14. git cherry-pick commit-number (获得commit-nummber对应的修改到当前的分支)
15. git push --set-upstream origin <Branch-name> (在git server创建 remote <Branch-name>分支)
16. 更改remote branch name
16.1 git branch -m newname (change local branch name)
16.2 git push origin :oldbranchname (delete remote branch name)
16.3 git push --set-upstream origin newname (change remote branch name)
19. git tag (list local tags)
20. git ls-remote --tags origin (list remote tags)
21. git push --delete origin tags/xxxxx (delete remote tags)
22. 如何撤回更改 revert last commit
22.1 git reset --hard HEAD~ (undo last commit)
22.2 git push origin +HEAD
23. 如何 git pull, git push 不同的remote repository
23.1 git remote -v
origin ssh://git@bitbucket.xxx.yyy.com:8000/zzz/project_a.git (fetch)
origin ssh://git@bitbucket.xxx.yyy.com:8000/zzz/project_a.git (push)
23.2 git remote add project_b(project name) project_b_url(project bitbucket url)
23.3 git remote -v
project_b ssh://git@bitbucket.xxx.yyy.com:8000/project_key/project_b.git (fetch)
project_b ssh://git@bitbucket.xxx.yyy.com:8000/project_key/project_b.git (push)
origin ssh://git@bitbucket.xxx.yyy.com:8000/zzz/project_a.git (fetch)
origin ssh://git@bitbucket.xxx.yyy.com:8000/zzz/project_a.git (push)
23.4 if you are in project_a repo, then use the following commands to git pull 或者 git push
git pull project_b project_b_branch
git push project_b project_b_branch