如何使用git上传自己的代码到github

在做项目和发表论文时,最后一步是把代码上传到github供社区参考。使用git工具可以方便的把整个文件夹的代码上传到自己github代码仓库中。

你首先需要安装git,默认安装即可,上传代码可分为3步:

1. 初始化自己文件夹为代码仓库

进入自己要上传的文件夹,用点击右键,“git bash here”,打开git 命令行终端。或者再git终端中使用cd github_code进入文件夹。
在这里插入图片描述

# 初始化文件夹,告诉git这个文件夹为代码仓库
$ git init
Initialized empty Git repository in D:/folder/github_code/.git/

# 获得github上要上传未知的代码仓库,可以在github 仓库中clone的位置复制即可,将远程代码仓库命名为 origin,可以命名成任何名字。
$ git remote add origin https://github.com/Xiaohui-Z/Plasmid_ML.git

# 先把github上的代码更新到本地,不然上传时容易出错
$ git pull origin master
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.
From https://github.com/Xiaohui-Z/Plasmid_ML
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master

$ ls
5k6mer_model.h5   model_train.py         README.md   testdata.csv
model_predict.py  prediction_result.txt  scaler.pkl

# 更新完毕后,把所有要上传的代码文件add到本地仓库中,并执行commit
$ git add 5k6mer_model.h5 model_train.py testdata.csv model_predict.py prediction_result.txt scaler.pkl
warning: LF will be replaced by CRLF in model_train.py.
The file will have its original line endings in your working directory

# -m后面是提示语,可以输入任何话语,提醒自己所做的修改
$ git commit -m "model upload"
[master 1e46a8f] model upload
 6 files changed, 536 insertions(+)
 create mode 100644 5k6mer_model.h5
 create mode 100644 model_predict.py
 create mode 100644 model_train.py
 create mode 100644 prediction_result.txt
 create mode 100644 scaler.pkl
 create mode 100644 testdata.csv

2. 更新远程仓库

以上的步骤是把本地的文件添加到本地仓库中了,下一步就是把本地仓库中的文件上传到github远程仓库中:

$ git push origin master
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10053
fatal: the remote end hung up unexpectedly44.00 KiB/s
Writing objects: 100% (8/8), 5.93 MiB | 269.00 KiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
fatal: the remote end hung up unexpectedly
Everything up-to-date

fatal 报错,刚才掉线了,重新试一下

$ git push origin master
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 5.93 MiB | 1.59 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0)
To https://github.com/Xiaohui-Z/Plasmid_ML.git
   0504365..1e46a8f  master -> master

成功上传

关于github,推荐博文史上最简单的 GitHub 教程,简单易懂,本人看了一上午下午就把项目代码上传到github了。

猜你喜欢

转载自blog.csdn.net/weixin_44022515/article/details/105976196