记一次将本地工程上传到github的过程

1、首先,进入本地工程所在文件夹,运行git init将工程初始化为git仓库:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject
$ git init
Initialized empty Git repository in C:/Users/XH/Desktop/toools/testApiProject/.git/

2、可以运行git status可以查看到此时本地仓库的变化:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git status
On branch master No commits yet Untracked files:
(use "git add <file>..." to include in what will be committed) .idea/
MyTestPackage/
README.md
__init__.py nothing added to commit but untracked files present (use "git add" to track)

3、从上面的输出可以看到,此时本地工程仓库的更改并没有存入暂存区。运行git add .将所有的更改提交到暂存区:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git add .
warning: LF will be replaced by CRLF in .idea/workspace.xml.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in MyTestPackage/.idea/workspace.xml.
The file will have its original line endings in your working directory

4、接着,运行git status查看,发现,更改已经存入暂存区:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git status
On branch master No commits yet Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: .idea/TestSB.iml
new file: .idea/misc.xml
new file: .idea/modules.xml
new file: .idea/workspace.xml
new file: MyTestPackage/.idea/MyTestPackage.iml
new file: MyTestPackage/.idea/misc.xml
new file: MyTestPackage/.idea/modules.xml
new file: MyTestPackage/.idea/workspace.xml
new file: MyTestPackage/A.py
new file: MyTestPackage/B.py
new file: MyTestPackage/__init__.py
new file: MyTestPackage/__pycache__/A.cpython-37.pyc
new file: MyTestPackage/__pycache__/__init__.cpython-37.pyc
new file: MyTestPackage/__pycache__/send_requests.cpython-37.pyc
new file: MyTestPackage/measurement.py
new file: MyTestPackage/send_requests.py
new file: README.md
new file: __init__.py

5、然后,运行git commit -m "first commit" 将本地工程仓库刚才存入暂存区的更改提交到git版本库:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git commit -m "first commit"
[master (root-commit) 06272ba] first commit
18 files changed, 1040 insertions(+)
create mode 100644 .idea/TestSB.iml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/workspace.xml
create mode 100644 MyTestPackage/.idea/MyTestPackage.iml
create mode 100644 MyTestPackage/.idea/misc.xml
create mode 100644 MyTestPackage/.idea/modules.xml
create mode 100644 MyTestPackage/.idea/workspace.xml
create mode 100644 MyTestPackage/A.py
create mode 100644 MyTestPackage/B.py
create mode 100644 MyTestPackage/__init__.py
create mode 100644 MyTestPackage/__pycache__/A.cpython-37.pyc
create mode 100644 MyTestPackage/__pycache__/__init__.cpython-37.pyc
create mode 100644 MyTestPackage/__pycache__/send_requests.cpython-37.pyc
create mode 100644 MyTestPackage/measurement.py
create mode 100644 MyTestPackage/send_requests.py
create mode 100644 README.md
create mode 100644 __init__.py

到这里,工程已经变成了git版本库了。

6、然后,需要将本地仓库与github上新建仓库(git@github.com:Sirxy/testApiProject.git)建立连接(即连接到远程仓库):

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git remote add origin git@github.com:Sirxy/testApiProject.git

至此,连接工作完成。

7、接着只需要将本地仓库推送(git push -u origin master)到远程github 上:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git push -u origin master
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 4 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (21/21), 9.46 KiB | 569.00 KiB/s, done.
Total 21 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To github.com:Sirxy/testApiProject.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

8、如果,在github上直接更改了你的代码,注意:一定要将远程仓库拉下来(在本地工程目录下运行git pull)同步到本地仓库,这样远程与本地就一致了:

XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$ git pull
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8 (delta 6), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (8/8), done.
From github.com:Sirxy/testApiProject
06272ba..1ce9e08 master -> origin/master
Updating 06272ba..1ce9e08
Fast-forward
MyTestPackage/measurement.py | 6 +++---
MyTestPackage/send_requests.py | 10 +++++-----
2 files changed, 8 insertions(+), 8 deletions(-) XH@DESKTOP-82MT9LU MINGW64 ~/Desktop/toools/testApiProject (master)
$

当然,也可以运行git clone git@github.com:Sirxy/testApiProject.git将远程仓库克隆到你的本地也是可以的。

注意:在到达第六步时,需要将自己本地PC的SSH公钥加入到自己的github(参见:版本控制神器——git的基本使用)。

关于生成公钥详细页可以参考git官网:生成 SSH 公钥

转载请备明出处:记一次将本地工程上传到github的过程

最新文章

  1. Ceph RGW 和 niginx 配置要点
  2. Configure the Windows Firewall to Allow SQL Server Access
  3. Android的onMeasure和onLayout And MeasureSpec揭秘
  4. ubuntu 更新 rtl8192cu 驱动
  5. Java SE 第二十三讲----static关键字and final关键字
  6. Spring boot教程
  7. java.sql.SQLException: Lock wait timeout exceeded --转
  8. excel筛选两列值是否相同,如果相同返回第三列值
  9. Using ROWNUM in Oracle
  10. Promise原理 &amp;&amp; 简单实现
  11. 传统web和mvc的区别
  12. JSP 网页格式判定执行哪一块html
  13. OpenGL一些函数详解(二)
  14. JavaScript--我发现,原来你是这样的JS:面向对象编程OOP[2]--(创建你的那个对象吧)
  15. 收集—— css实现垂直居中
  16. UVA 12009 - Avaricious Maryanna(数论)
  17. vue单页面应用刷新网页后vuex的state数据丢失的解决方案
  18. 未来-区块链-Micron:区块链永远不会忘记:内存对这项革命性技术的推动作用
  19. 第2周个人作业:WordCount
  20. Deployment Descriptor Web.xml

热门文章

  1. 关于./xhost: unable to open display问题的解决
  2. Unity5-ABSystem(一):AssetBundle原理
  3. 学习笔记01HTML
  4. Mybatis:CRUD操作
  5. 「卡常」我T死了我好桑心,我不会卡常。
  6. 【转载】InstantRun 原理——深度剖析 AndroidStudio 2.0
  7. FHQ treap学习(复习)笔记
  8. PHP路径指定web路径的方法
  9. python——多线程
  10. solr 本地搭建