在项目开发中简单使用git

git的详细说明以及教程 http://www.runoob.com/git/git-tutorial.html

git常用命令
http://www.cnblogs.com/springbarley/archive/2012/11/03/2752984.html

本教程基于我们已经拥有了一个GitHub上的远程仓库

使用工具
windowns https://git-scm.com/downloads
Linux apt-get install git

注意事项

克隆到本地之后默认为master分支,不能直接在master分支上直接修改代码。需要自己创建分支。比如创建两个分支一个是用个人姓名命名myname, 用来提交到远程仓库,另一个名命为test用来测试开发。

在idea项目开发主界面的右下角有git分支提示,提示个人当前的分支。同时也可以切换分支。还可以自动提交代码变更。

#首先把该远程仓库代码克隆到我们的电脑, 由于是私有仓库所以需要验证用户名密码,只有仓库创建者邀请加入才有权限
$ git clone https://github.com/cacacai/edas

#创建分支test
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (master)
$ git branch test

#创建分支cai
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (master)
$ git branch cai

#切换分支
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (master)
$ git checkout test
Switched to branch 'test'

#在test分支下进行开发,比如创建文件
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (test)
$ vim test.txt

#把个人修改添加到test分支中
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (test)
$ git add test.txt
$ git commit -m "test"
[test cd8c132] test
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

#切换到cai分支并把test分支的修改合并到cai中
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (test)
$ git checkout cai
Switched to branch 'cai'

cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (cai)
$ git merge test
Updating 9417be4..cd8c132
Fast-forward
 test.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt

#确认代码无误后推送到远程,提交本地cai分支作为远程的cai分支,如果不存在,远程的github就会自动创建一个cai分支
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (cai)
$ git push origin cai:cai
Username for 'https://github.com': cacacai
Counting objects: 2673, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2623/2623), done.
Writing objects: 100% (2673/2673), 26.47 MiB | 928.00 KiB/s, done.
Total 2673 (delta 630), reused 0 (delta 0)
remote: Resolving deltas: 100% (630/630), done.
To https://github.com/cacacai/edas.git
 * [new branch]      cai -> cai

#把远程分支同步到本地
cai@DESKTOP-PE2L2A5 MINGW64 /e/Workspaces/workspace/edas (cai)
$ git pull origin master
Username for 'https://github.com': cacacai
From https://github.com/cacacai/edas
 * branch            master     -> FETCH_HEAD
Updating cd8c132..5844af3
Fast-forward
 README.md | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 README.md
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值