In Eclipse java project, change git repository from an old one to a new one - eclipse

I have a project in Eclipse that is associated with an old repository in Gitlab. The branch being used is called Test.
I created a new repository in Gitlab (and it only has the README.md file in it). It only has one branch: master.
I need to change the Eclipse project so that it no longer refers to the old repository (and old branch) but instead - refers to the new repository (with he master branch).
How can this be done?
TIA
Update
#Rizwan - thanks for the info. I did the following:
cd to the directory with the code
#initialize the repository
git init
#add reference to the repository I needed
git remote add origin "git#myrepo.com:WORK/<my-repository>.git"
#got what was currently in the repository
git pull origin master
#added code (not in the repository)
git add -A
#commit the code
git commit -m "first commit with code"
#sent it up
git push origin master
There was another message I used as a base (but I cant find it now)
TIA

We can directly perform this operation in Eclipse itself.
Goto - CurrentProject(Right Click) -> Team -> Remote -> Configure push to upstream -> Change(URI)

This might help
Locate your project on your local computer. You can do this by running:
cd /path/to/repo
Then check and confirm a list of all of your existing remotes. To do this run this command:
git remote -v
Change the URL of the remote with the git remote set-url command:
git remote set-url origin gitlab#gitlab.mydomain:root/testproject.git
Check back with the step 2 whether your repo has changed
Refresh/Clean Build your Eclipse project

Related

Connect to github server

I have the ip, useename and password of the github server, which uses gitlab, and I need to connect to it and manage files. What should I do?
I'm assuming you're asking how to manage/change files within a git repository. If you're asking something else, I've missed the point, apologies.
Firstly you will need 'git' on your local machine - install it with your package manager or download and install it from the git website.
Once git is installed you can clone a repository (which contains a set of files, and ends in .git) using the git clone command. Run git clone --help for more information on this, but if you already know the address of your git server and the path to the repository, it will look something like as follows:
git clone https://git-server.url/path/to/repo.git
Note that the URL you should use will depend on the configured transport protocol (git, ssh, http[s]) of your git server.
Next, you should makes some local configurations, for example, from a terminal:
git config user.name "your_username"
git config user.email "someone#example.com"
You can add --global to both of these command if you want these changes to persist outside of the current git repo.
Having a cloned repository automatically checks out an initial 'branch' on which you can make changes to files within your repository. See the git docs for a detailed explanation of a branch.
Files can be added, removed or renamed/moved using git add, git rm or git mv respectively.
Finally, you must commit your changes and push them
git commit -m "A message describing your changes"
git remote will confirm the name of the default remote (repo location). In this case, it is assumed to be origin. You can then push your changes to an existing branch (viewed using git branch -r), assumed to be master below:
git push origin master
Here you would be merging your master branch with the remote one. Clearly your permissions/project conventions will dictate what you can/should do to this repo.

best way to export Eclipse project to GitHub

I need to export an Eclipse project to GitHub. I am using Eclipse-Mars with the eGit plugin. I have spent hours reading documentation, tutorials, and posts and see that there are basically two ways
Create an Eclipse project and a local Git repository. Commit to local repository. Create a repository on GitHub. Push the Eclipse project to the repository on GitHub. When I try this, I get the error "rejected non-fast-forward". I have no idea why. I did create a .gitignore on GitHub when I created the repository - is that causing a problem?
Create a repository on GitHub. In Eclipse, clone this repository and then add files. Commit to local repository, then push. This works, but I end up with a weird configuration on GitHub:
reponame/myprojname/src
when I would prefer the more normal
reponame/src
Which method is the correct way to proceed? Why do I get the push error in the first method, and why the strange folder layout in the second?
You first need to pull the github code into you local machine.
=> git remote add origin
=> git pull origin master
will automatically fetch and merge the github repo with your local copy. You may need to resolve some conflicts that could be generated due to 3-way merge.
After all this, you can use -
=> git push -u origin master
For the second Point,
If you want src/ directory directly under reponame/ on github, then you should execute git clone after creating the project in eclipse and git clone should be executed inside the myprojectname/ directory.
When you created the .gitignore file on GitHub, you created a commit in the repository that isn't in your local copy. You'll need to add the GitHub repo as a remote, pull the change, and then push your local changes:
git remote add origin <path to your repository>
git pull origin master
git push -u origin master

initialize bitbucket repository with existing project using netbeans

I have an existing netbeansproject (about 20 classes, java) which i want to manage using a private repository. So I choosed bitbucket (have an acount and repository). I initialised a local git repository (using netbeans).
How can i connect my project with the bitbucket repository using netbeans?
When i try to "push" it i get this error message "Cannot connect to the remote repository at https://OsmosisDJones#bitbucket.org/OsmosisDJones/inba.git"
This is an old question, still if anyone needs the answer.
git add --all
git commit -m "Initial Commit"
git remote add origin https://...
git push -u origin master
You can find this info on bitbucket after you create the repository.

C9 created workspace before repository

I made the mistake of creating a workspace before a repository on C9.io.
As a result I do not have version control. Naturally, I want to use Git for my project before make any more changes. Everything I have tried has failed. I would rather not have to copy all the code I've made into a new work space with an already set up repository. So if anyone has any suggestions or answers to this problem, via Command line, GUI or anything else that would be wonderful.
cloud9 doesn't do any special magic when cloning from a git repository, and you can add a remote the standard way you would do locally:
git init initialize a git repository in the current folder
git add -a add everything (or what you want)
git commit -m "initial commit" commit
git remote add origin git#github.com:<me>/<repo>.git add your repo
git push origin HEAD:master push HEAD to master branch in the remote you just added

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.