idea中将项目与github关联

创建github

  • 在github中创建一个账号
  • 下载并安装git
  • 安装成功后打开Git Bash,输入下列命令,设置git全局用户名和邮箱
    enter image description here
  • 在IDEA中设置Git,在’File-->Setting->Version Control-->Git-->Path to Git executable选择你的git安装后的git.exe文件,然后点击Test,测试是否设置成功
    enter image description here
  • 在IDEA中设置GitHubFile-->Setting->Version Control-->GibHub
      Host:github.com
      Token:点击Create API Token,输入在github中注册的用户名和密码生成token
      点击Test,测试是否连接成功
    enter image description here
  • 创建本地仓库,VCS-->Import into Version Control-->Create Git Repository...
    enter image description here
  • 在弹框中选中项目所在的位置,点击OK,此时项目文件全部变成红色(若选中其他位置,则git-->add不可点选,不知为何)
    enter image description here
  • 上传项目到本地仓库,项目右键选择Git-->add,此时项目文件变成绿色,此时文件只是处于暂存区,并没有真正进入到版本库中
    enter image description here
    enter image description here
  •  项目右键Git--> Commit Directory,在弹窗中输入Commit Message,点击commit,此时项目文件从暂存区真正进入版本库中,项目文件变成白色
    enter image description here
    enter image description here
    enter image description here
  • 上传项目到GitHub中,VCS-->Import into Version Control-->Share Project on GitHub,在弹框中输入仓库名和描述,点击Share,即可是上传,中间会弹窗输入GitHub的用户名和密码(已输入过用户名和密码并记住的不会再次弹框输入),上传成功后IDEA右下角会给出提示
    enter image description here
    enter image description here
    enter image description here
  • 提交修改文件到GitHub
    新增文件(红色),右键–>Git-->add,将新增的文件加入本地仓库,此时文件变绿色
    修改文件(蓝色)
    在项目右键–>Git-->Commit Directory,查看有变动的文件并输入Commit Message,点击Commit and Push...
    提交后会进行语法检查,若存在错误或警告会给出确认提示,点击Commit,弹出Push框,点击Push,上传GitHub成功
    enter image description here
    enter image description here
    enter image description here
    enter image description here
  • 如果要是多人协作开发,那么不仅要将自己的代码上传,还要将队友的代码down下来,根据idea的套路,他的上传时push,那么下载就是pull了
    enter image description here