前言
痛点:白天上班,没有研究明白的代码想回家继续研究,但是又不想把电脑带回家,这怎么办 ?
解决方案:只需要把代码上传到 GitHub 上,回家从 GitHub 下载就好了。
目录
一 创建远程仓库,并上传项目
下面详细介绍操作步骤!
前提: 1、电脑安装 git 客户端;2、要有一个 GitHub 账号,
git下载安装:官网下载
GitHub 账号免费注册 官网地址
接下来上操作步骤!
第一步、点击下图中红色框按钮 “Start a project”,目的是新建一个项目。
第二步、根据提示输入信息,
注意 下图最后一栏--Initialize this repository with a README 项目初始化,一定不要勾选,不然会遇到很苦恼的问题。这个选项就是告诉你,如果你是上传一个新的项目,请跳过,反之勾选。
点击 “Create repository”,OK,项目创建完毕,跳转页面展示的内容是几种上传方式
上图最开始,让你选择远程URL方式,HTTPS 呢还是 SSH,GitHub 推荐使用HTTPS,SSH 方式需要本机创建密钥。
选择好哪一种远程URL方式之后,下面会自动生成上传命令行,上图荧光黄下
首先采用SSH方式:
1. git init # 初始化仓库
2. git add . # 上传到仓库的文件(‘.’ 同 ‘*’,上传全部文件)
3. git commit -m "first commit" # 上传的文件在本地仓库中创建
4. ssh-keygen -t rsa -C "[email protected]" # 创建 SSH 密钥
5. git remote add origin [email protected]:baicun/springBootDemo.git # 连接GitHub 仓库
6. git push -u origin master # 上传项目到Github,如果是SSH上传,则无需密码
在我们要上传的项目下,右键- Git Bash Here,弹出命令窗口,开始顺序执行
生成密钥:ssh-keygen -t rsa -C "[email protected]"
过程中,一路 Enter,无需修改
执行完成以后,在C盘会生成 .ssh文件,
右键- Git Bash Here,弹出命令窗口,输入查看命令,查看生成的密钥,并且拷贝
这里还可以看一下状态:ssh -T [email protected],会有successfully,说明成功。
super@LAPTOP-C56SSORU MINGW64 ~/.ssh
$ ssh -T [email protected]
Hi baicun! You've successfully authenticated, but GitHub does not provide shell access.
然后页面转到GitHub页面,进行密钥配置。
在弹出页面上,Title 随便写,密钥呢,就是上面生成的密钥,增加保存。
继续执行命令-连接远程仓库,上传项目
OK,因为踩过坑,所以这一次很顺利。
HTTPS方式创建远程仓库:
git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/baicun/microboot.git
git push -u origin master
灰常顺利,就是在最后一步需要验证GitHub用户名和密码,执行记录如下:
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot
$ git init
Initialized empty Git repository in E:/projects/demo/microboot/.git/
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in .mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/.gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/.mvn/wrapper/maven-wrapper.properties.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/mvnw.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/mvnw.cmd.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/pom.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/src/main/java/cn/mldn/BaseApplication.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in base/src/test/java/cn/mldn/BaseApplicationTests.java.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in mvnw.cmd.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in pom.xml.
The file will have its original line endings in your working directory.
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot (master)
$ git commit -m "first commit"
[master (root-commit) fe5e846] first commit
17 files changed, 977 insertions(+)
create mode 100644 .gitignore
create mode 100644 .mvn/wrapper/maven-wrapper.jar
create mode 100644 .mvn/wrapper/maven-wrapper.properties
create mode 100644 base/.gitignore
create mode 100644 base/.mvn/wrapper/maven-wrapper.jar
create mode 100644 base/.mvn/wrapper/maven-wrapper.properties
create mode 100644 base/mvnw
create mode 100644 base/mvnw.cmd
create mode 100644 base/pom.xml
create mode 100644 base/src/main/java/cn/mldn/BaseApplication.java
create mode 100644 base/src/main/java/cn/mldn/controller/BaseController.java
create mode 100644 base/src/main/resources/application.properties
create mode 100644 base/src/test/java/cn/mldn/BaseApplicationTests.java
create mode 100644 base/src/test/java/cn/mldn/MicrobootBaseTest.java
create mode 100644 mvnw
create mode 100644 mvnw.cmd
create mode 100644 pom.xml
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot (master)
$ git remote add origin https://github.com/baicun/microboot.git
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot (master)
$ git push -u origin master
fatal: TaskCanceledException encountered.
▒▒ȡ▒▒һ▒▒▒▒▒▒
Username for 'https://github.com': baicun
Enumerating objects: 28, done.
Counting objects: 100% (28/28), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (28/28), 47.33 KiB | 5.26 MiB/s, done.
Total 28 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/baicun/microboot/pull/new/master
remote:
To https://github.com/baicun/microboot.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
super@LAPTOP-C56SSORU MINGW64 /e/projects/demo/microboot (master)
$
二 删除远程仓库
上面创建远程仓库,失败或是想重新创建时,我们就要删除现有的项目,具体步骤如下:
拉到页面最下边
这里需要正确输入要删除的项目名称,名称正确,下面的按钮才会允许点击,执行删除操作。