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

来源:互联网 发布:淘宝760的lamy2000 编辑:程序博客网 时间:2024/05/22 01:32

  • 概述
  • 步骤
    • GIT软件安装
    • 初始化本地maven项目为 Git 项目
    • 将所有文件放进新的本地 git 仓库
    • 将添加的文件提交到仓库
    • GitHub上创建项目 copy项目地址
    • 回到命令行终端界面将本地仓库关联到远程仓库
    • 提交代码到 GitHub 仓库
    • Github上查看项目
    • Github提示信息
    • 在Spring Tool Suite中连接GITHUB
  • 另外一个Java项目托管到github上的完整操作

概述

打算将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.gitMr.Yang@Mr MINGW64 /d/workspace/workspace-sts/SpringMaster (master)$ git remote -vorigin  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 masterCounting 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 -> masterBranch master set up to track remote branch master from origin.

这里写图片描述


8. Github上查看项目

这里写图片描述


Github提示信息

仓库创建成功后,Github如下提示信息,可以指导我们将项目托管到GITHUB 仓库

or create a new repository on the command lineecho "# SpringMaster" >> README.mdgit initgit add README.mdgit commit -m "first commit"git remote add origin https://github.com/yangshangwei/SpringMaster.gitgit push -u origin master…or push an existing repository from the command linegit remote add origin https://github.com/yangshangwei/SpringMaster.gitgit push -u origin master…or import code from another repositoryYou 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 initInitialized 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.classMr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)$ git remote add origin https://github.com/yangshangwei/commonUtils.gitMr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)$ git remote -vorigin  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 masterCounting 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 -> masterBranch master set up to track remote branch master from origin.Mr.Yang@Mr MINGW64 /d/workspace/ws-java-base/commonUtils (master)$

这里写图片描述