Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库

简介: Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库

概述


打算将SpringMaster项目托管到GitHub,方便查阅

最终效果如下:

aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDI1ODE1NjUy.png


步骤

1.GIT软件安装

现在并安装GIT

我们这里使用这里写  aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMwMzQ0OTM0.png 通过命令行的方式将本地项目托管到GITHUB。


2.初始化本地maven项目为 Git 项目


本地项目目录: D:\workspace\workspace-sts\SpringMaster

打开GIT BASH,进入到项目所在目录


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMwOTAzNzI5.png

执行命令

$ git init


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMxMDE1Njgy.png

此时会在目录中创建一个 .git 隐藏文件夹,如下



aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMxMDU4Mjc4.png

3.将所有文件放进新的本地 git 仓库

$ git add .


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMxNDU1NjAy.png

如果你本地已经有 .gitignore 文件,会按照已有规则过滤不需要添加的文件。如果不想要添加所有文件,可以把 . 符号换成具体的文件名


4. 将添加的文件提交到仓库

git commit -m "Initial commit"



aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMxNjE4Nzgz.png


5. GitHub上创建项目 ,copy项目地址

创建过程省略,最后如下所示:


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMxODQyNTAw.png

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命令查看结果

aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyMTA3NTk2.png


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.

aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyMzIwMDY4.png

8. Github上查看项目


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyNDI1NDA2.png



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.



aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyNjE4NTI5.png


9. 在Spring Tool Suite中连接GITHUB


Windows—Show View选择Git Repositories


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyODQ2NDg1.png


选择 Add an existing local Git Repository to this view


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMyOTM4NTI1.png


选择本地的GIT项目

aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMzMDM5Nzk5.png

切换到GIT视图 或者Spring视图 都可以看到了

aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMzMTUyNjg3.png


文件操作,右键 Team


image.png


或者下载一个GitHub Desktop

File-Add local Repository


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODI5MDIxNDU2NTQz.png


如下


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODI5MDIxNTQ1NjA0.png

选择你要操作的项目即可


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODE5MDMzNDE1NzQz.png


或者直接使用命令行的方式最为方便。



另外一个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)
$


aHR0cDovL2ltZy5ibG9nLmNzZG4ubmV0LzIwMTcwODI5MDIyMzM3MjMz.png


相关文章
|
1天前
|
JavaScript 网络安全 开发工具
[保姆级-从0到1]利用hexo+github托管实现搭建个人博客
[保姆级-从0到1]利用hexo+github托管实现搭建个人博客
|
1天前
|
SQL Oracle 前端开发
Oracle效率分析,Github标星25K+超火的前端实战项目
Oracle效率分析,Github标星25K+超火的前端实战项目
|
1天前
|
前端开发
Github项目分享——免费的画图工具drow,最新前端面试题整理
Github项目分享——免费的画图工具drow,最新前端面试题整理
|
3天前
|
安全 网络安全 开发工具
【GitHub】清空 GitHub 仓库中的所有内容,只保留 `README.md` 文件
【GitHub】清空 GitHub 仓库中的所有内容,只保留 `README.md` 文件
8 2
|
3天前
|
开发工具 git
Git项目如何配置,如何上传至GitHub。其详细步骤
Git项目如何配置,如何上传至GitHub。其详细步骤
11 0
|
3天前
github设置仓库可见性 私人仓库设置
github设置仓库可见性 私人仓库设置
|
3天前
|
网络安全 数据安全/隐私保护
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
解决git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Pleas
|
3天前
|
弹性计算 Shell 开发工具
自动化Git仓库清理与维护
【4月更文挑战第30天】
7 0
|
3天前
|
弹性计算 运维 Shell
自动化GitHub仓库活跃度分析
【4月更文挑战第30天】
7 0
|
10月前
|
Java 开发工具 数据库

热门文章

最新文章