Linux下git的安装及简单使用

  1. [root@localhost /]# yum install git     
  2. [root@localhost /]# git config --global user.name "Your Name"  
  3. [root@localhost /]# git config --global user.email "email@example.com"  
  4. [root@localhost /]# mkdir uter     
  5. [root@localhost /]# cd uter  
  6. [root@localhost uter]# git init    
  7. 初始化空的 Git 版本库于 /uter/.git/  
  8. [root@localhost uter]# ls -ah     
  9. .  ..  .git  
  10.   
  11.   
  12.   
  13.   
  14. //前面几步操作我们已经成功安装了git并创建了一个版本库,如果需要把这个版本库取消那么直接把(.git)这个文件删除就可以了   
  15. [root@localhost uter]# rm -rf .git  
  16.   
  17. //现在我们试试把文件上传到版本库  
  18. [root@localhost uter]# vim git.txt   
  19. [root@localhost uter]# git add git.txt    
  20. [root@localhost uter]# git status  
  21. # 位于分支 master  
  22. #  
  23. # 初始提交  
  24. #  
  25. # 要提交的变更:  
  26. #   (使用 "git rm --cached <file>..." 撤出暂存区)  
  27. #  
  28. #   新文件:    git.txt  
  29. #  
  30. [root@localhost uter]# git commit -m "linux test git"  
  31. [master(根提交) c87e19d] linux test git  
  32.  1 file changed, 1 insertion(+)  
  33.  create mode 100644 git.txt  
  34. [root@localhost uter]# git log  //查看版本信息  
  35. //在这里我直接对接我github上的远程仓库[已经建好的]  
  36. [root@localhost uter]#  git remote add origin  https://github.com/xuedongyue/learngit.git  
  37. [root@localhost uter]# git merge origin/master  
  38. [root@localhost uter]# git push -u origin master  
  39.   
  40. 接下来我们回到浏览器返回 Github 创建的仓库刷新一下,就可以看到文件已上传到Github上:  
  41.   
  42.   
  43.   
  44. 查看当前的远程库:  
  45.   
  46. [root@localhost uter]# git remote   
  47. [root@localhost uter]# git remote -v // -v 参数,可以看到每个别名的实际链接地址。  
  48.   
  49.   
  50. 提取远程仓库:  
  51.   
  52. 1、从远程仓库下载新分支与数据  
  53. [root@localhost uter]# git fetch    
  54.  //该命令执行完后需要执行git merge 远程分支到你所在的分支。  
  55. 2、从远端仓库提取数据并尝试合并到当前分支  
  56. [root@localhost uter]# git pull    
  57. //该命令就是在执行 git fetch 之后紧接着执行 git merge 远程分支到你所在的任意分支。  
  58. 假设你配置好了一个远程仓库,并且你想要提取更新的数据,你可以首先执行  
  59. git fetch [alias] 告诉 Git 去获取它有你没有的数据,然后你可以执行  
  60. git merge [alias]/[branch] 以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。  
  61.   
  62. [root@localhost uter]# git fetch origin   
  63. [root@localhost uter]# git merge origin/master (远程库名/分支名)  
  64.   
  65.   
  66. 推送到远程仓库:  
  67.   
  68. [root@localhost uter] git push origin  master   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值