Git本地文件提交到GitHub

  在本地电脑上创建文件夹之后提交到GitHub:

  首先确保你的账号已经和GitHub相关联,在此基础上,采用以下步骤(以test为例):

  • 在GitHub上创建一个repository,名字要与你本地项目文件夹的名字相同,都为test.
  • 然后在Git Bash中进入到本地的test的文件目录下,我的是在d/workspace/test中
1 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
2 $ ll
3 total 2
4 -rw-r--r-- 1 G 197121 23 12月 22 10:52 name.txt
5 -rw-r--r-- 1 G 197121 27 12月 22 10:53 xx.txt
  • 克隆GitHub上的repository的SSH

1 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
2 $ git clone git@github.com:JennyGao811/test.git
3 Cloning into 'test'...
4 //输入你的密码
5 Enter passphrase for key '/c/Users/G/.ssh/id_rsa':
6 warning: You appear to have cloned an empty repository.
  •  远程
 1 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
 2 //远程链接
 3 $ git remote add origin git@github.com:JennyGao811/test.git
 4 
 5 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
 6 //添加本地文件,这里是添加全部
 7 $ git add .
 8 warning: LF will be replaced by CRLF in name.txt.
 9 The file will have its original line endings in your working directory.
10 warning: LF will be replaced by CRLF in xx.txt.
11 The file will have its original line endings in your working directory.
12 
13 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
14 //提交
15 $ git commit -m 'commit all test'
16 [master (root-commit) 6e5381b] commit all test
17  2 files changed, 3 insertions(+)
18  create mode 100644 name.txt
19  create mode 100644 xx.txt
20 
21 G@LAPTOP-T07M310F MINGW64 /d/workspace/test (master)
22 //提交到远程
23 $ git push -u origin master
24 Enter passphrase for key '/c/Users/G/.ssh/id_rsa':
25 Counting objects: 4, done.
26 Delta compression using up to 4 threads.
27 Compressing objects: 100% (2/2), done.
28 Writing objects: 100% (4/4), 301 bytes | 301.00 KiB/s, done.
29 Total 4 (delta 0), reused 0 (delta 0)
30 To github.com:JennyGao811/test.git
31  * [new branch]      master -> master
32 Branch 'master' set up to track remote branch 'master' from 'origin'.
  • 然后到GitHub上刷新一下页面,就可以发现项目已经提交上去。

原文地址:https://www.cnblogs.com/gaojiaxu/p/8085006.html