注:变量参数都会被“( )”所标注
1.远程仓库连接 git remote add (remotename )(resporistyURL)
remotename:自定义一个本地的分支名,任何不存在的分支名都可以
repositoryURL:远程仓库链接
2.分支操作
创建分支 git branch [分支名] (是 `git checkout -b [分支名]`的缩写)
新建分支并切换到那个分支上去 git checkout -b (new branchname)
分支切换 git checkout [分支名]
合并分支 git merge [分支名] (注:将分支名合并到本分支上)
删除分支(删除分支之前必须先切换到别的分支) git branch -d (branchname)
3.Git与远程仓库的相应操作
git add .
git commit -m “(注释)”
git fetch (remotename) (branchname)
git push (remotename) (branchname) (branch大多是branchname)
4.Git撤销 git add 操作 git rm --cached -r .(“.”点不要落了)
--cached指不要删除本地文件
5.所遇到的特殊报错
fatal: refusing to merge unrelated histories
解决办法:$ git pull 后面加--allow-unrelated-histories完事
6.替换分支
```
git checkout oldMaster // 切换到要被替换的分支
git reset --hard newMaster // 将oldMaster 替换成 newMaster
git push origin oldMaster --force // 再推送到远程仓库
```
如果仅仅替换远程
```git push origin develop:master -f```
即可
7.删除分支
删除本地分支 git branch -d branchName //这种删除需要branchName先合并到主分支上再进行删除
git branch -D master = git brach --delete --force master
删除远程分支 git push --delete origin/brach
仅删除追踪分支 git push --remotes --delete origin/master