美文网首页
Git 克隆 GitHub 仓库到本地

Git 克隆 GitHub 仓库到本地

作者: bei6 | 来源:发表于2019-03-16 12:26 被阅读0次

前提

  1. 已经进行过身份设置
  2. GitHub 上已经存在本项目

克隆

以这个仓库为例,复制其 SSH(不推荐使用HTTPS)


在喜欢的位置打开终端(我的是 ubuntu),执行克隆命令:

git clone git@github.com:bey6/myrepository.git

这里提示说我克隆了一个空仓库,你是对的...

推送

进入克隆的文件夹
复制仓库中此段代码:



该段代码功能如下描述:
添加了一个 README.md 文件,并且首先提交到本地仓库,然后添加远程仓库为我们新建的 myrepository.git 仓库,最后执行推送。
此时刷新我们的 github repository,已经可以看到 README.md 文件了。

自己尝试推送

robinu@bey-pc:~/workspace/test/myrepository$ echo "# 我的第一次提交" >> test.md
robinu@bey-pc:~/workspace/test/myrepository$ echo "这是我的第一次提交" >> test.md
robinu@bey-pc:~/workspace/test/myrepository$ git add test.md 
robinu@bey-pc:~/workspace/test/myrepository$ git commit -m "我自己的提交尝试"
[master 143e42a] 我自己的提交尝试
 1 file changed, 2 insertions(+)
 create mode 100644 test.md
robinu@bey-pc:~/workspace/test/myrepository$ git push -u origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 336 bytes | 336.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:bey6/myrepository.git
   72ac0b8..143e42a  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
robinu@bey-pc:~/workspace/test/myrepository$ 

推送分为 3 步:

  1. 添加要推送的文件 (git add test.md)
  2. 提交到本地仓库(git commit -m "我自己的提交")
  3. 推送到远程仓库(git push -u origin master)这里是说推送主分支库

相关文章

网友评论

      本文标题:Git 克隆 GitHub 仓库到本地

      本文链接:https://www.haomeiwen.com/subject/ivijmqtx.html