Linux下git的安装及简单使用

本文介绍了如何在Linux环境下安装配置Git,并演示了从初始化版本库、添加文件、提交更改到推送远程仓库等一系列基本操作。
    [root@localhost /]# yum install git     
    [root@localhost /]# git config --global user.name "Your Name"  
    [root@localhost /]# git config --global user.email "email@example.com"  
    [root@localhost /]# mkdir uter     
    [root@localhost /]# cd uter  
    [root@localhost uter]# git init    
    初始化空的 Git 版本库于 /uter/.git/  
    [root@localhost uter]# ls -ah     
    .  ..  .git  
      
      
      
      
    //前面几步操作我们已经成功安装了git并创建了一个版本库,如果需要把这个版本库取消那么直接把(.git)这个文件删除就可以了   
    [root@localhost uter]# rm -rf .git  
      
    //现在我们试试把文件上传到版本库  
    [root@localhost uter]# vim git.txt   
    [root@localhost uter]# git add git.txt    
    [root@localhost uter]# git status  
    # 位于分支 master  
    #  
    # 初始提交  
    #  
    # 要提交的变更:  
    #   (使用 "git rm --cached <file>..." 撤出暂存区)  
    #  
    #   新文件:    git.txt  
    #  
    [root@localhost uter]# git commit -m "linux test git"  
    [master(根提交) c87e19d] linux test git  
     1 file changed, 1 insertion(+)  
     create mode 100644 git.txt  
    [root@localhost uter]# git log  //查看版本信息  
    //在这里我直接对接我github上的远程仓库[已经建好的]  
    [root@localhost uter]#  git remote add origin  https://github.com/xuedongyue/learngit.git  
    [root@localhost uter]# git merge origin/master  
    [root@localhost uter]# git push -u origin master  
      
    接下来我们回到浏览器返回 Github 创建的仓库刷新一下,就可以看到文件已上传到Github上:  
      
      
      
    查看当前的远程库:  
      
    [root@localhost uter]# git remote   
    [root@localhost uter]# git remote -v // -v 参数,可以看到每个别名的实际链接地址。  
      
      
    提取远程仓库:  
      
    1、从远程仓库下载新分支与数据  
    [root@localhost uter]# git fetch    
     //该命令执行完后需要执行git merge 远程分支到你所在的分支。  
    2、从远端仓库提取数据并尝试合并到当前分支  
    [root@localhost uter]# git pull    
    //该命令就是在执行 git fetch 之后紧接着执行 git merge 远程分支到你所在的任意分支。  
    假设你配置好了一个远程仓库,并且你想要提取更新的数据,你可以首先执行  
    git fetch [alias] 告诉 Git 去获取它有你没有的数据,然后你可以执行  
    git merge [alias]/[branch] 以将服务器上的任何更新(假设有人这时候推送到服务器了)合并到你的当前分支。  
      
    [root@localhost uter]# git fetch origin   
    [root@localhost uter]# git merge origin/master (远程库名/分支名)  
      
      
    推送到远程仓库:  
      
    [root@localhost uter] git push origin  master    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值