||
一、在本地创建一个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
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-27 07:34
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社