之前都是在终端使用git,现在很多工程使用Qtcreator开发,发现Qtcreator中也集成了git的功能,所以想尝试配置一下Qtcreator在里面使用git。
开始之前在网上找了一些资料,很有用,受到很多的启发,但是实际使用中还是遇到一些问题,所以把自己动手操作的过程整理一下,可以在以后用到的时候查阅,如果能帮助有类似需求的人更好。
我的Qtcreator在ubuntu 12.04系统中,代码仓库是放到github上面。
1.在ubuntu 12.04中安装git
在终端输入下面命令进行在线安装,需要电脑能上网。
sudo apt-get install git
安装成功后输入 git --version查询git版本,如下图所示,说明git安装成功。
2.git 设置用户名和邮箱
git config --global user.name "username"
git config --global user.email “useremail”
“username”替换为自己的用户名,“useremail”替换为自己邮箱。
3.生成ssh密钥
ssh-keygen -t rsa -C "your_email"
"your_email"是自己的邮箱。执行后一直回车到完成,生成的公钥在~/.ssh/id_rsa.pub 。
4. github添加自己的密钥
"Settings"-->"SSH and GPG Keys",然后添加密钥。
5.在本地建立仓库
在本地工程目录使用 git init创建版本库,
然后使用git add . 加入所有文件,
最后git commit -m ‘你的注释’ 提交。
6.在github建立仓库
登录github后选择Your repositories,再选择New新建仓库。
7.推送本地仓库到github
git remote add origin git@github.com:danielliu2017/HelloWorld.git
git push -u origin master
第一行中的远端仓库地址使用ssh,不要使用Https。
8.Qtcreator中进行配置(指定git路径)
9. Qtcreator中推送
先提交本地修改Tools-->Git-->Local Repository-->commit
最后,在Qtcreator执行push。
Tools-->Git-->Remote Repository-->push