五、在IDEA中使用GIt版本控制并将本地代码上传至Github

  • 一、安装git

      Git工具下载:https://git-scm.com/downloads 从官网下载。安装很简单,基本都是下一步。

   安装完的第一件事情就是创建一个Git用户:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

    还有一个比较重要的命令就是帮助命令:

$ help help
help: help [-dms] [pattern ...]
Display information about builtin commands.

Displays brief summaries of builtin commands. If PATTERN is
specified, gives detailed help on all commands matching PATTERN,
otherwise the list of help topics is printed.

Options:
-d output short description for each topic
-m display usage in pseudo-manpage format
-s output only a short usage synopsis for each topic matching
PATTERN

Arguments:
PATTERN Pattern specifiying a help topic

Exit Status:
Returns success unless PATTERN is not found or an invalid option is given.

  其它也有很多很常用很重要的命令,但我们要在使用的过程中去记忆比较好。

  • 二、创建github账户

          gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub。官方网站:https://github.com/ 

   没有账号的话,根据填写相应的注册信息,便可以申请一个账号。对于程序员来说github是一个比较好的工具和网站。

  • 三、在IDEA中配置git

          打开IDEA后 请按照步骤    File -》Settings -》Version Control -》Git -》 Path to Git executable 接下来的看截图吧!
          

       引入Git的路径之后,点击Test,如果可用会弹出如上窗口。

  • 四、IDEA项目引入VCS

  打开IDEA工程项目后, 在菜单栏 VCS-》import  into Version Control -》Create Git Repository -》你的工程目录。 这样我们就把idea工程创建了一个Git Repository了,在工程文件目录下就会多了一个
.git文件夹。这时项目中的文件会变成红色,表示文件提交到了本地git仓库当中。
  然后呢?
  

 

 

  • 五、本地 Repositories上传到Github的 Repositories

   由于本地Git仓库和Github仓库之间的传输是通过SSH加密的,所以连接时需要设置一下,创建SSH KEY。先看一下你C盘用户目录下有没有.ssh目录,有的话看下里面有没有id_rsa和id_rsa.pub这两个文件,

     有就跳到下一步,没有就通过下面命令创建:

   ssh-keygen -t rsa -C "youremail@example.com"

  

    

  登录Github,找到右上角的图标,打开点进里面的Settings,再选中里面的SSH and GPG KEYS,点击右上角的New SSH key,然后Title里面随便填,再把刚才id_rsa.pub里面的内容复制到Title下面的Key内容框里面,

  最后点击Add SSH key,这样就完成了SSH Key的加密。具体步骤也可看下面:

       

       

    

  然后自己创建一个仓库,使用下面红色字的命令,就可以把本地的库上传到github。

…or create a new repository on the command line

 
echo "# C-" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/zhuguangjin/C-.git
git push -u origin master

…or push an existing repository from the command line

 
git remote add origin https://github.com/zhuguangjin/C-.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.

 

posted @ 2017-11-01 22:43  纯新手  阅读(14893)  评论(0编辑  收藏  举报