git将本地文件上传到github - Go语言中文社区

git将本地文件上传到github


GUI版本

总结
git init(初始化本地文件夹)—github上新建同名库-remote(GUI上远程连接)-stagechanged(GUI上缓存)-commit(GUI上提交)-push(GUI推送到网上)

在windows系统客户端安装git工具

git init

在将要上传的文件夹内右键打开git bash here,输入命令git init

Administrator@PC-20161015WFCW MINGW64 ~/Desktop/standardweb
$ git init
Initialized empty Git repository in C:/Users/Administrator/Desktop/standardweb/.git/

or

在“本地文件”中添加“.git文件”,用于git管理。
进入本地文件夹,右击鼠标-单击Git Init Here-生成.git文件夹。
这里写图片描述

在github创建仓库用于存储管理本地文件,示例:Blog。

点击账号前的加号(Create New)–New repository,根据引导创建一个Blog仓库。
这里写图片描述

远程添加github上的Blog仓库。

1)进入本地文件夹下-右击鼠标-Git Gui-远端(remote)-Add…
这里写图片描述
2)获取github中Blog仓库的地址。
这里写图片描述
3) 在Add Remote窗口中填写名字、Location。
名字:Blog
Location:粘贴刚刚复制的Blog仓库路径
最后单击“Add”。
这里写图片描述

将“未缓存的改动”缓存到“已缓存的改动”

这里写图片描述
Stackoverflow上的回答

In git-gui, there are 2 methods to move all the files from Unstaged to
Staged.

1) Press Ctrl+I which will move all the Unstaged files to staged files

2) Click “Stage Changed” button in the bottom panel above “Signoff”
and “Commit”

将本地文件内容即“已缓存的改动”,提交git管理的master分支上。

这里写图片描述

将本地文件上传到github上去。

单击Git Gui界面“上传”–“上传”窗口随意勾选一个或多个传输选项–点击“上传”–上传Blog过程中需要输入github的登录账号和密码。
这里写图片描述

在github上查看本地文件Blog项目是否上传成功。

这里写图片描述


全命令版本

Administrator@PC-20161015WFCW MINGW64 ~/Desktop
$ mkdir git@local_to_github
#新建文件夹
Administrator@PC-20161015WFCW MINGW64 ~/Desktop
$ cd git@local_to_github
#cd到文件夹中
Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github
$ git init
#初始化文件夹(增加.git文件)
Initialized empty Git repository in C:/Users/Administrator/Desktop/git@local_to_github/.git/

Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ git status
#查看里面的文件
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        django.pdf

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

Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ git add .
#通过git add把项目添加到仓库(或git add .把该目录下的所有文件添加到仓库,注意点是用空格隔开的)

Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ git commit -m "first commit"
#用git commit把项目提交到仓库,-m后面是注释内容
[master (root-commit) bc25cea] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 django.pdf


Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ ssh-keygen -t rsa -C "youremail@qq.com"
#创建SSHkey
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:******
#把电脑中【C/用户/Administrater/.ssh】文件夹中的id_rsa.pub中的内容复制粘贴到github的settings中的SSH keys上面。
#在Github上创建一个仓库

Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ git remote add origin https://github.com/Geek-Lee/git-local_to_github.git
#把github的地址https和本地关联
Administrator@PC-20161015WFCW MINGW64 ~/Desktop/git@local_to_github (master)
$ git push -u origin master
#关联后把本地的文件推送到github上
#由于新建的远程仓库是空的,所以要加上-u这个参数,等远程仓库里面有了内容之后,下次再从本地库上传内容的时候只需下面这样就可以了:
$ git push origin master

git remote add origin git地址
git 远程 添加 起源 git地址
另外,这里有个坑需要注意一下,就是在上面第七步创建远程仓库的时候,如果你勾选了Initialize this repository with a README(就是创建仓库的时候自动给你创建一个README文件),那么到了第九步你将本地仓库内容推送到远程仓库的时候就会报一个failed to push some refs to https://github.com/guyibang/TEST2.git的错。

这里写图片描述

这是由于你新创建的那个仓库里面的README文件不在本地仓库目录中,这时我们可以通过以下命令先将内容合并以下:

git pull --rebase origin master

这里写图片描述
这时你再push就能成功了

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/GeekLeee/article/details/72857935
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-03-08 10:55:42
  • 阅读 ( 1742 )
  • 分类:Go开源项目

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢