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

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!

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 :
either go to Window > Show View > Other... then select Git > Git repositories or click the Git repositories icon in the set of icons in the right
expand the repository to see "Remotes", right click and Create Remote
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", ...)
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"; if in GitHub you first copy the uri then it might be automatically filled in
"Finish" then "Save and Push" or "Save and Fetch" according to what you chose 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

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.

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.

Related

How to import a specific project from github

How to import a specific project from github ? I dont want to clone the entire repository
I just want to clone only a portion of repository .
For eg this url https://github.com/eugenp/tutorials
has many projects but I just want to clone only spring-boot-crud project .
Here is the url for spring-boot-crud project.
https://github.com/eugenp/tutorials/tree/master/spring-boot-modules/spring-boot-crud
Thank you .
You can look into a git sparse-checkout: that command is made to checkout only part of a Git repository. This assume the latest Git 2.26 though.
And I mean Git-core, as in Git SCM, not Egit (which does not support the new sparse-checkout command)
Even though the command is new and still experimental, it should be useful in your case.
git clone --no-checkout /url/a/repo
cd repo
git sparse-checkout init --cone
git sparse-checkout set spring-boot-modules/spring-boot-crud
Then open the relevant project in your Eclipse.
Create a project in the Git repo (.project, in the root folder of your repo)
That will give you:
git clone -n https://github/git/git git2
cd git2
git sparse-checkout init
git sparse-checkout set Documentation
At this point, you have the repository git/git with only the folder Documentation checked out (everything else is not in the working tree)
# create an empty project in C:\path\to\git2 in Eclipse
As you can see, all the other files not checked out are not displayed in the Git staging view. Only the ones currently checked out and modified are listed.
The first step must be done in command-line because JGit does not support the sparse-checkout directive (see but 383772 and change 33)

unable to push source folders from eclipse to GIT

steps I have followed
created a repository
convert to maven project(configure -> convert to maven project)
added facet nature.
created folder structure (src/main/java, src/main/resources, src/test/java, src/test/resources)
After that right click on the project -> GIT bash terminal
git init
git commit -m "first commit"
git remote add origin URL
git push -u origin master
After doing all this when I do a checkout(clone repository -> import projects) I am unable to see the source folder like src/main/java.
screen shots attached
project created with folder structure
folder structure when I did a checkout
A git checkout is used to change the branch you are currently working on. It's probably not what you are willing to do here, is it?
My guess regarding your issue is that your git commit didn't commit your newly created files because they were not tracked when you committed your changes.
When you perform a git init, it basically inits a new empty repository, which means that your files are not tracked by default. You first need to git add them before committing.
My explanation is a bit confusing but I guess that if you first git add your files and then commit, it should work.
EDIT: You don't seem to be talking about git checkout here, but rather cloning. This gives even more sense to my answer, I pretty much think that your files have never been committed because you never added them to the staging area.

How Do I Push an Existing Eclipse Project Up to Bitbucket With EGIT?

I have a project for an interview I need to get onto Bitbucket. I normally use Github, so the slight change is throwing me off. I coded the project, tested it, and it works fine. Now I want to get it up on the repository, but can't. I installed EGIT to my Eclipse instance on my local, and while it will attach itself to the empty online repository it won't allow me to import my local code to a do a push and commit.
Can anyone advise on the simplest way I can get this taken care of?
With EGit on Neon: right-click on project > Team > Push branch...., you'll see the push dialog and a button to create a new remote. Click this button, configure the bitbucket repo, Finish.
Then the repo should be available in the Push Dialog. So select it as target and press Finish.
In Bitbucket you can import project from github.
But if you want to change git remote origin and send the whole project again to Bitbucket get to this file : .git/config and change the [remote "origin"] section to the Bitbucket repo http or ssh and then:
git add all or git add .
git commit -m "last commit massage ..."
git push -u origin master
I recommand to use Gitlab instead of Bitbucket for private repo.

Cloning a github repo into an existing project?

I have a project in Eclipse that I want to put on github, so I went to github and created the repos for them, but I want to clone them right into the folder where the files are stored in my eclipse workspace. How can I do this?
EDIT: When I try it, the github app says it can't clone because the folder isn't empty.
EDIT 2: Will this work? Changing the name in eclipse to rename the project folder, then cloning the repo to the name I want, in the workspace, then renaming the eclipse project so they merge and I can commit the new files.
GitHub has a guide explaining how to put an existing project on GitHub.
You should not clone the repository, but add the GitHub repository as a remote to a local repository you create yourself.
Go to your project folder and initialize a local repository with git init
Add and commit all your project files to the local repository. (e.g. git add . and git commit -m "message")
Add the GitHub repository as a remote. git remote add origin *github repository URL* (Verify with git remote -v)
Push your project to GitHub with git push origin master.
If you already have committed files to the GitHub repository, it is still possible.
Initialize your local repository.
Add GitHub as the remote.
Pull from GitHub.
Add and commit your project.
Push you project to GitHub
First add the remote as follows
git remote add origin <GIT URL>
Then simply do the following (MAke sure to commit any of your local files)
git pull --allow-unrelated-histories

How to push code to root of git repository (GitHub)

I am very new to git and have been facing the problem below for 4-5 days now.
I have a project that I want to share on GitHub and I created a repo (https://github.com/jitix/cfs/tree/master/cfs) for the same.
Here is what I did:
Checked out the code from svn using Eclipse (Juno).
Removed svn related files and 'cleaned' the folder by doing Team > Disconnect.
Created a local git repository (using both via eclipse and cli on different occasions).
Added appropriate .gitignore file.
Committed the code into the local repo (somehow eclipse moves the folder there, but not an issue). Eclipse made me choose the $repo/cfs as the folder where the code is committed. I could not commit it to $repo.
Now I want to push it into GitHub. Tried out the following:
Method 1 (eclipse):
Team > Remote > Push
Use refs/heads/master as both source ref and dest ref and commit.
Method 2 (cli from the $repo/cfs directory):
git remote add origin jitix#https://github.com/jitix/cfs.git
git push -u origin master
Issue:
In both cases, I am getting the cfs directory under the GitHub repo, not at the root (as most projects have). Also, each folder has a .. link to the parent folder in it (something that I have never seen on GitHub, and something that does not happen if I push using svn).
I checked out my code from svn, created a local repo and committed the code into
You need to create the git repository inside the folder that you want to upload. You've created it one level above the cfs folder and then pushed that, you want to run git init while inside cfs and then go from there.
Try in commandline instead using eclipse and follow the steps that GitHub recommends.
Go inside the directory of your project and type:
git init
git commit -a -m "first commit"
git remote add origin jitix#https://github.com/jitix/cfs.git
git push -u origin master
It should work, although is pretty much what you were doing.