heberoxx 发表于 2018-1-14 13:36:50

使用Git将本地仓库与GitHub远程仓库相关联

  这篇文章详细讲解了如何生成SSH,并链接到GitHub,http://www.cnblogs.com/Gabriel-Wei/p/6564060.html
  1.如果你的GitHub里面没有仓库,就自己生成一个,如图所示
https://images2015.cnblogs.com/blog/986868/201703/986868-20170317094911291-348400380.png
  2.如果你有自己仓库,想在电脑本地新建一个,你需要将GitHub的仓库地址复制下来,注意使用的是ssh,如图所示,
https://images2015.cnblogs.com/blog/986868/201703/986868-20170317095145541-903315045.png
  3.在电脑本地新建一个文件夹,将我们的远程仓库clone下来,
  

我是在d盘,test文件夹下面,直接右击选择git bash here  
Administrator@LS--20160817QEI MINGW32 /d/test
  

  
输入下面的命令
  
$ git clone git@github.com:Gabrielkaliboy/markdown.git
  

  
git会返回下面的文字
  
Cloning into 'markdown'...
  
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
  
remote: Counting objects: 12, done.
  
remote: Compressing objects: 100% (8/8), done.
  
), reused 11 (delta 0), pack-reused 0
  
Receiving objects: 100% (12/12), 23.26 KiB | 0 bytes/s, done.
  
Resolving deltas: 100% (1/1), done.
  
Checking connectivity... done.
  

  此时我们再去看我们的文件夹目录,已经顺利将文件clone到了本地
  4.我们切入下载下来的文件夹(markdown),进行一些操作,我们可以看到多了一个单词,master
  

$ cd markdown  

  5.我们往markdown文件夹里面放多个文件,然后查看一下当前的状态
  

在markdown里面新建文件里面,查看一下当前的状态  
$ git status
  

  
git会给我们返回这个信息
  
On branch master
  
Your branch is up-to-date with 'origin/master'.
  
Untracked files:
  (use "git add
<file>..." to include in what will be committed)  

  images/webDaily/
  "markdown\344\275\277\347\224\250\346\212\200\345\267\247.md"
  "\345\211\215\347\253\257\346\227\245\345\270\270\350\256\260\345\275\225.md"
  

  
nothing added to commit but untracked files present (use "git add" to track)
  

  6.将多个文件同时提交到暂存区(或者将多个被修改的文件同时进行提交)
  

$ git add -A .  

  没有任何返回
  7.我们再次查看一下当前的状态
  

输入命令:  
$ git status
  

  
git返回:
  
On branch master
  
Your branch is up-to-date with 'origin/master'.
  
Changes to be committed:
  (use "git reset HEAD
<file>..." to unstage)  

  new file:   images/webDaily/1.jpg
  new file:   "markdown\344\275\277\347\224\250\346\212\200\345\267\247.md"
  new file:   "\345\211\215\347\253\257\346\227\245\345\270\270\350\256\260\345\275\225.md"
  

  8.将暂存区的文件提交到GitHub分支
  

-m右面是此次提交的信息说明,输入命令:  
$ git commit -m"提交新的文件"
  

  
Git会给我们返回:
  
提交新的文件
  3 files changed, 111 insertions(+)
  create mode 100644 images/webDaily/1.jpg
  create mode 100644 "markdown\344\275\277\347\224\250\346\212\200\345\267\247.md"
  create mode 100644 "\345\211\215\347\253\257\346\227\245\345\270\270\350\256\260\345\275\225.md"
  

  9.再次查看当前的本地仓库状态
  

输入命令:  
$ git status
  

  
Git返回的信息:
  
On branch master
  
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
  
nothing to commit, working directory clean
  

  他提示我们将分支提交到主分支
  10还没有结束,我们需要将我们的文件推送到分支
  

输入:  
$ git push -u origin master
  

  
Git返回:
  
Counting objects: 7, done.
  
Delta compression using up to 2 threads.
  
Compressing objects: 100% (6/6), done.
  
Writing objects: 100% (7/7), 7.85 KiB | 0 bytes/s, done.
  
Total 7 (delta 0), reused 0 (delta 0)
  
To git@github.com:Gabrielkaliboy/markdown.git
  cd8d69d..eea6990master -> master
  
Branch master set up to track remote branch master from origin.
  

  11.此时再次查看一下仓库状态
  

$ git status  
On branch master
  
Your branch is up-to-date with 'origin/master'.
  
nothing to commit, working directory clean
  

  只要你对工作区没有任何的修改,工作区就是干净的
页: [1]
查看完整版本: 使用Git将本地仓库与GitHub远程仓库相关联