首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Git-将已有的项目转换为GIT项目托管到 GITHUB 仓库

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

作者头像
小小工匠
发布2021-08-16 16:40:44
发布2021-08-16 16:40:44
8560
举报
文章被收录于专栏:小工匠聊架构小工匠聊架构

文章目录

概述

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

最终效果如下:


步骤

1.GIT软件安装

现在并安装GIT

我们这里使用

通过命令行的方式将本地项目托管到GITHUB。


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

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

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

执行命令

代码语言:javascript
复制
$ git init

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


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

代码语言:javascript
复制
$ git add .

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


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

代码语言:javascript
复制
git commit -m "Initial commit"

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

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

https://github.com/yangshangwei/SpringMaster.git 复制仓库地址


6. 回到命令行终端界面,将本地仓库关联到远程仓库

代码语言:javascript
复制
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 仓库

代码语言:javascript
复制
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 仓库

代码语言:javascript
复制
…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

代码语言:javascript
复制
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)
$
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017/08/19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 概述
  • 步骤
    • 1.GIT软件安装
    • 2.初始化本地maven项目为 Git 项目
    • 3.将所有文件放进新的本地 git 仓库
    • 4. 将添加的文件提交到仓库
    • 5. GitHub上创建项目 ,copy项目地址
    • 6. 回到命令行终端界面,将本地仓库关联到远程仓库
    • 7. 提交代码到 GitHub 仓库
    • 8. Github上查看项目
    • Github提示信息
    • 9. 在Spring Tool Suite中连接GITHUB
  • 另外一个Java项目托管到github上的完整操作
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档