文章目录
概述
打算将SpringMaster项目托管到GitHub,方便查阅
最终效果如下:
步骤
1.GIT软件安装
现在并安装GIT
我们这里使用通过命令行的方式将本地项目托管到GITHUB。
2.初始化本地maven项目为 Git 项目
本地项目目录: D:\workspace\workspace-sts\SpringMaster
打开GIT BASH,进入到项目所在目录
执行命令
$ git init
此时会在目录中创建一个 .git 隐藏文件夹,如下
3.将所有文件放进新的本地 git 仓库
$ git add .
如果你本地已经有 .gitignore
文件,会按照已有规则过滤不需要添加的文件。如果不想要添加所有文件,可以把 .
符号换成具体的文件名
4. 将添加的文件提交到仓库
git commit -m "Initial commit"
5. GitHub上创建项目 ,copy项目地址
创建过程省略,最后如下所示:
https://github.com/yangshangwei/SpringMaster.git 复制仓库地址
6. 回到命令行终端界面,将本地仓库关联到远程仓库
Mr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master)
$ git remote add origin https://github.com/yangshangwei/SpringMaster.git
Mr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master)
$ git remote -v
origin https://github.com/yangshangwei/SpringMaster.git (fetch)
origin https://github.com/yangshangwei/SpringMaster.git (push)
通过 git remote -v
命令查看结果
7. 提交代码到 GitHub 仓库
Mr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master)
$ git push -u origin master
Counting objects: 590, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (574/574), done.
Writing objects: 100% (590/590), 150.56 KiB | 0 bytes/s, done.
Total 590 (delta 180), reused 0 (delta 0)
remote: Resolving deltas: 100% (180/180), done.
To https://github.com/yangshangwei/SpringMaster.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
8. Github上查看项目
Github提示信息
仓库创建成功后,Github如下提示信息,可以指导我们将项目托管到GITHUB 仓库
…or create a new repository on the command line
echo "# SpringMaster" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/yangshangwei/SpringMaster.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/yangshangwei/SpringMaster.git
git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
9. 在Spring Tool Suite中连接GITHUB
Windows—Show View选择Git Repositories
选择 Add an existing local Git Repository to this view
选择本地的GIT项目
切换到GIT视图 或者Spring视图 都可以看到了
文件操作,右键 Team
或者下载一个GitHub Desktop
File-Add local Repository
如下
选择你要操作的项目即可
或者直接使用命令行的方式最为方便。
另外一个Java项目托管到github上的完整操作
打开GitBash
Mr.Yang@Mr MINGW64 ~
$ cd d:
Mr.Yang@Mr MINGW64 /d
$ cd workspace/ws-java-base/commonUtils/
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils
$ git init
Initialized empty Git repository in D:/workspace/ws-java-base/commonUtils/.git/
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git add .
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git commit -m "Intial commit"
[master (root-commit) 42fb8f6] Intial commit
18 files changed, 438 insertions(+)
create mode 100644 .classpath
create mode 100644 .project
create mode 100644 .settings/org.eclipse.core.resources.prefs
create mode 100644 .settings/org.eclipse.jdt.core.prefs
create mode 100644 .settings/org.eclipse.m2e.core.prefs
create mode 100644 pom.xml
create mode 100644 src/main/java/com/artisan/commonUtils/App.java
create mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtil.java
create mode 100644 src/main/java/com/artisan/commonUtils/getPath/PathUtilDemo.java
create mode 100644 src/main/java/com/artisan/commonUtils/mail/MailServer.properties
create mode 100644 src/main/java/com/artisan/commonUtils/mail/SendEmailUtil.java
create mode 100644 src/test/java/com/artisan/commonUtils/AppTest.java
create mode 100644 target/classes/com/artisan/commonUtils/App.class
create mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtil.class
create mode 100644 target/classes/com/artisan/commonUtils/getPath/PathUtilDemo.class
create mode 100644 target/classes/com/artisan/commonUtils/mail/MailServer.properties
create mode 100644 target/classes/com/artisan/commonUtils/mail/SendEmailUtil.class
create mode 100644 target/test-classes/com/artisan/commonUtils/AppTest.class
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git remote add origin https://github.com/yangshangwei/commonUtils.git
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git remote -v
origin https://github.com/yangshangwei/commonUtils.git (fetch)
origin https://github.com/yangshangwei/commonUtils.git (push)
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$ git push -u origin master
Counting objects: 44, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (28/28), done.
Writing objects: 100% (44/44), 10.15 KiB | 0 bytes/s, done.
Total 44 (delta 0), reused 0 (delta 0)
To https://github.com/yangshangwei/commonUtils.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)
$