xi123的个人博客分享 http://blog.sciencenet.cn/u/xi123

博文

git使用

已有 1520 次阅读 2018-3-9 16:19 |个人分类:git学习|系统分类:科研笔记


一、在本地创建一个git库

   

    mkdir filename

    cd filename

    git init        #把这个目录变成Git可以管理的仓库

    ls -ah          #查看.git文件


二、在一个git库中添加文件

   

    git add filename        #告诉Git,把文件添加到仓库

    git commit -m "xxxx"  # 告诉Git,把文件提交到仓库  

    

三、从本地库到远程仓库

     

    首先在github上创建一个空库(不需要初始化readme.md);

    然后进入本地库git bash here(本地库初始化git init);

    再添加本地库与远程库的联系;

        方式一:git remote add origin git@github.com:github_usrname/Repository_name.git

        方式二:git remote add origin https://github.com/xiqiangucas/paper_reading.git

    添加后,远程库的名字就是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库,方式一是ssh方式不需要提供用户名和密码,方式二需要输入用户名和密码。

    最后,将本地库的内容提交到远程库。

        git push -u origin master        #将本地库所有内容推送到远程库

    把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。

    之后再做推送使用:

        git push origin  master    #把本地master分支的最新修改推送至GitHub


四、错误类型与解决办法


    错误1:fatal: remote origin already exists.

    解决:git remote rm origin

  错误2:If no other git process is currently running, this probably means a git process crashed in this repository earlier. Make sure no other git process is running and remove the file manually to continue.

    解决:rm -f ./.git/index.lock


五、参考

【1】https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

【2】https://blog.csdn.net/wh_19910525/article/details/8161365

【3】https://blog.csdn.net/yywan1314520/article/details/51566924






https://blog.sciencenet.cn/blog-3360373-1103056.html

上一篇:自动文摘(三)
下一篇:机器学习之朴素贝叶斯
收藏 IP: 36.102.220.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-28 11:20

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部