平台:qt creator 4.11.0
安装git:https://git-scm.com/downloads,配置好远程仓库
本地仓库上传至Gitee
1、创建本地qt项目,选择“添加到版本管理系统”-“git”,默认“master”单分支,之后可以再添加
2、“工具”-“Git”-“Local Repository”-“Commit”,提交分支
3、“工具”-“Git”-“Local Repository”-“分支列表”,可以看到“Git Branches”-“本地分支”下有了“master”分支
4、gitee创建空仓库
5、右键点击“Git Branches”-“Remote Branches”或者“工具”-“Git”-“Remote Repository”,找到“Mange Remotes”打开一个“远程”对话框,进去添加远程仓库的信息,Name填“origin”,URL填刚才创建的gitee仓库的HTTP
6、“远程”对话框里有一个“Push”按钮,实测无法推送,报错
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin master
需要通过git gui来推送,“工具”-“Git”-“Git Tools”-“Git Gui”,找到“Push”按钮点击推送成功
后来发现,好像要先安装git再安装qt creator才能使用creator来操作。
为了能在qtcreator中直接push,可以为本地分支绑定远程分支,在git bash中执行:
git branch --set-upstream-to=origin/<branch> master
其中的
origin/< branch>
指的是远程分支名,origin是第5步输入的Name,也可以是别的名字,斜杠后跟着分支名,如origin/master。
git bash通过 Git Gui-Repository-Git Bash打开。
实测这条指令必须首先通过Git GUI push一次之后才能成功执行,否则会提示错误:
requested upstream branch ‘origin/master’ does not exist
新建本地仓库(从Gitee克隆仓库)
新建项目-“import Project”-“Git Clone”,“Repository”填写Gitee仓库的HTTP,“Branch”填写克隆分支名如“master”,“Path”填项目根路径,“Directory”填项目文件夹名,“下一步”开始克隆
更新本地仓库(从Gitee拉取)
“工具”-“Git”-“Remote Repository”-“Pull”,有可能报一下错误:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
The command "C:\Program Files\Git\cmd\git.exe pull" terminated with exit code 1.
这里可能跟上面无法Push的原因是一样的,此时可以通过git gui拉取:
1、“Remote”-“Fetch from”-远程仓库名,
2、“Merge”-“Local Merge”-“Tacking Branch”-远程仓库分支-“Merge”
为了能在qtcreator中直接pull,也可以按照提示执行:
git branch --set-upstream-to=origin/<branch> master
其他技巧
新建分支:在“Git Branches”里右键点击“本地分支”,Add
切换分支:在“Git Branches”里右键点击目标分支,Checkout
历史信息:在“Git Branches”里双击对应的分支即可显示 Git Log,点击SHA-1可以显示详细的修改内容(Git Show)
比较分支:在“Git Branches”里右键点击另一个分支,Diff