Intellij IDEA 如何使用 git 插件将项目上传到远程分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14051525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:10:19  来源:igfitidea点击:

Intellij IDEA how to upload project to remote branch with git plugin?

gitintellij-idea

提问by Dmytro Danylyk

I have Intellij IDEA 12.0.1 I am using build-in Git plugin. I am able to create local repository. Now I want to upload my source code to remote repository. Can I do this with Intellij IDEA plugin?

我有 Intellij IDEA 12.0.1 我正在使用内置 Git 插件。我能够创建本地存储库。现在我想将我的源代码上传到远程存储库。我可以用 Intellij IDEA 插件做到这一点吗?

Thank you.

谢谢你。

回答by Dmytro Danylyk

You can't upload your local Git repository to remote using IntelliJ IDEA plugin. For this you need to use Git Bashor Git client, for example Source Tree.

您无法使用 IntelliJ IDEA 插件将本地 Git 存储库上传到远程。为此,您需要使用Git Bash或 Git 客户端,例如Source Tree

To create local Git repository with IntelliJ IDEA plugin

使用 IntelliJ IDEA 插件创建本地 Git 存储库

  1. In IntelliJ IDEA menu VCS -> Import into Version Control -> Create Git Repository
  2. In pop up window select your project and click ok.
  3. Commit all necessary files to you local branch master
  1. 在 IntelliJ IDEA 菜单中 VCS -> Import into Version Control -> Create Git Repository
  2. 在弹出窗口中选择您的项目并单击确定。
  3. 将所有必要的文件提交到您的本地分支 master

To upload local repository to remote using Git Bash

使用 Git Bash 将本地存储库上传到远程

  1. Open Git Bashand navigate to your project folder e.g cd 'D:\projects\TestProject'
  2. In Git Bashgit remote add origin http//IP/path/to/repository
  3. In Git Bashgit push origin master
  4. In IntelliJ IDEAright-click on project select Synchronize 'TestProject'
  5. In IntelliJ IDEAright-click on project select Git -> Repository -> Branches -> origin/master -> Checkout as new local branch
  1. 打开Git Bash并导航到您的项目文件夹,例如 cd'D:\projects\TestProject'
  2. Git Bash 中git remote add origin http//IP/path/to/repository
  3. Git Bash 中git push origin master
  4. IntelliJ IDEA 中右键单击项目选择Synchronize 'TestProject'
  5. IntelliJ IDEA 中右键单击项目选择Git -> Repository -> Branches -> origin/master -> Checkout as new local branch

To upload local repository to remote using Source Tree

使用 Source Tree 将本地存储库上传到远程

  1. In Source TreeFile -> Openand navigate to your project folder e.g cd 'D:\projects\TestProject'
  2. In Source TreeRepository -> Add Remote, you should see Repository Settingswindow enter image description here
  3. Click Addbutton, and fill Remote detailsenter image description here
  4. Finally click Okbutton Now you should be able to do pull/push using IntelliJ IDEA plugin.
  5. In IntelliJ IDEAright-click on project select Synchronize 'TestProject'
  6. In IntelliJ IDEAright-click on project select Git -> Repository -> Branches -> origin/master -> Checkout as new local branch
  1. 源树中File -> Open并导航到您的项目文件夹,例如 cd'D:\projects\TestProject'
  2. Source Tree 中Repository -> Add Remote,您应该看到Repository Settings窗口 在此处输入图片说明
  3. 单击添加按钮,并填写远程详细信息在此处输入图片说明
  4. 最后单击Ok按钮现在您应该可以使用 IntelliJ IDEA 插件进行拉/推。
  5. IntelliJ IDEA 中右键单击项目选择Synchronize 'TestProject'
  6. IntelliJ IDEA 中右键单击项目选择Git -> Repository -> Branches -> origin/master -> Checkout as new local branch


Now you should be able to do pull/pushusing IntelliJ IDEAplugin.

现在您应该能够使用IntelliJ IDEA插件进行拉/推

回答by taher

It is possible in Intellij IDEA.
You should add a remote repository for your local repository in git bash by below command.

这在 Intellij IDEA 中是可能的。
您应该通过以下命令在 git bash 中为本地存储库添加远程存储库。

git remote add origin YOUR_REMOTE_REPOSITORY_ADDRESS.
for example
git remote add origin https://gitlab.com/my_account/my_repository.git

In Intellij IDEA when you want to commit any change to repository use ctrl + kand it will show you a window like below image. In this window you can choose commit and pushso it will commits and push change to local and remote repository.
enter image description hereAlso if you want to only push to remote repository use ctrl + shift + kto pushing changes.
I hope this answer helps you.

在 Intellij IDEA 中,当您想要提交对存储库使用的任何更改时ctrl + k,它会显示一个如下图所示的窗口。在此窗口中,您可以选择commit and push将更改提交并推送到本地和远程存储库。
在此处输入图片说明此外,如果您只想推送到远程存储库,请使用ctrl + shift + k推送更改。
我希望这个答案对你有帮助。

回答by Karthic Raghupathi

I had the same problem and I believe this is still the case with IDEA 12 unless I'm mistaken:

我遇到了同样的问题,我相信 IDEA 12 仍然如此,除非我弄错了:

An alternative to using the command line would be SourceTree (available for Mac & Win) to manage remotes or manage Git/Hg repositories completely. It is a free GUI client from Atlassian (no affiliation disclosure).

使用命令行的替代方法是 SourceTree(适用于 Mac 和 Win)来管理远程或完全管理 Git/Hg 存储库。它是来自 Atlassian 的免费 G​​UI 客户端(无从属关系披露)。

You can download it here.

你可以在这里下载。