How do I create a remote git repository in EGit and link it to an existing Eclipse project?

元气小坏坏 提交于 2019-11-29 11:30:17

问题


I am using Eclipse Helios and EGit. I am new to Git. I have an existing Eclipse project for an Android app I would like to place in Git. Can someone please share some instructions on how to setup a Git repo on a shared folder, and place the existing project into this git repo using EGit? I have tried a variety of options with no success.

Thanks!


回答1:


I had the same question (how to do it in Eclipse / eGit), and I just found the answer to the question stated in the title :

  1. go in Window > Show Views > Others select Git repositories
  2. expand the repository to see "Remotes", right click and Create Remote
  3. choose the option : fetch will tell eclipse you're only allowed to read (which is the correct option if you don't want/have the right to push on that repo). then name that remote repository like you want (the first is usually named "origin", but you can have "prod", "test-server", ...)
  4. click on change to specify the uri of the repository. You can paste on the first field the complete uri you would type after "git clone".
  5. "Finish" then "Save and Push" or "Save and Fetch" according to what you choosed in 3°

Also, for creating a new project in Eclipse from an existing git repository with eGit, all you have to do is to go in File > Import...and choosing Git/Projects from Git. Then follow the steps




回答2:


You can do everything from the command line instead:

Do this in the root of the project:

git init

Do the same in the folder where you want your blessed or central repository:

git init --bare

In the local repository, add a readme file and commit it:

echo "testing" > readme
git add readme   
git commit -m "initial commit"

Now link and push your changes to the central repository:

git remote add origin //server/share/repodir
git push -u origin master

Hope this gets you started.

You can use egit later if you like, but there is nothing wrong with using git separately.




回答3:


See http://wiki.eclipse.org/EGit/User_Guide

If you only want one project in your git repo, Team>Share Project will turn that project into a git repo. You can then create another repo on your share, and push your project repo to the shared folder repo.

If you want a repo with multiple projects, your best bet is to create the project in an external location to the workspace. Then you can create the git repo in the folder above your project.



来源:https://stackoverflow.com/questions/5790333/how-do-i-create-a-remote-git-repository-in-egit-and-link-it-to-an-existing-eclip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!