How should I correctly push my project to github using eclipse? - eclipse

I work in Eclipse. I have a maven project and usually, I commit and push it to my remote repo on GitLab. Now I want to push this project to a brand new GitHub repo. I've already created an empty repo on GitHub and pulled it to my local machine. So I already have a corresponding empty local repo too. The thing is I don't understand how to push my project to my new local repository and then push it to Github.
Usually, I use Egit but I can use the command line as well.
Maybe my logic is wrong? What should I do to have my project on GitHub then?
Thank you in advance.

I'm not sure if I understand your problem, if you were already pushing to GitLab with Egit. Have you tried to do it yet? Are you getting errors?
You should be able to use Egit the same way by committing to your local repo and then pushing to GitHub instead of GitLab.
The only difference would be having to use your GitHub credentials (or associating your SSH key to GitHub), and then specifying your GitHub repository.
https://wiki.eclipse.org/EGit/User_Guide#GitHub_Tutorial
The only thing that you had to keep in mind is to make sure your branch specs match. I think you might see "HEAD" by default, but you can change that to "master" if that's all you have.

Related

Cloned and Pushed a Forked Repo Successfully, Which Does NOT Read on Github

Using git bash, Windows 10 64x.
Successfully forked a repo, and cloned it to mine.
Was able to read it on my computer.
Also, there was no technical issue in pushing the repo (to my repo, not as an upstream) - can't click on 'datasharing'.
But I cannot read it on GitHub, and can't figure out why.
Please help me.
datasharing seems to be a submodule there. This means the original ower of the repo is using code from a foreign repo in his project. In order for you to use this code in a cloned repo you will have to obtain it separately after cloning your main repo. Imagine this like cloning a repo into a repo. This method is often used and perfect for referencing to external code while keeping all the advantages of version management rather than copying a static version of a library into your project.
Obtain the external code as follows:
Clone your repo as usual and cd into the folder.
git submodule init
git submodule update
The external code will be integrated into your repo and pushed/pulled with it. Not being able to click that folder seems to me as if github is aware of its existence but lacks the content.
For an exact reference on this topic you may want to read up on submodules in the docu found here.

How can collaborators push their changes to my repo in GitHub

First I have created one project in Eclipse and committed to my GitHub using below commands:git init
git add .
git commit -m "first commit"
git remote add origin URI of my repo
git push -u origin master
Then I modified one file in Eclipse and committed to GitHub from Eclipse through creating remote and giving the remote URI of the repo.
I added my team member through add collaborator.
Then he downloaded my project and made a change in a file in Eclipse.
Now, how can he push that modified file to my GitHub repository from within Eclipse?
We have done one thing. He created a remote and gave the URI of my repo. But still we are unable to commit that file.
You need to add your colleague as a collaborator. This can be done in the desired GitHub repo via Settings > Collaborators (you need to type in your password again). Afterwards they have those permissions.
UPDATE
Sorry and good morning ;)
I overlooked that you already added your partner as a collaborator. Another possible reason for your situation could be in the Temporary interaction limits where you can, amongst others, limit the interaction with your repo to prior contributors.
If that doesn't help. Please add some more informations about your colleague's git logs.
UPDATE 2
#Rahul K regarding your comment (which you better add to your question, for faster recognition), your colleague first needs to integrate the remote changes via git pull origin master in order to be able to push his or her changes afterwards. But be aware that he or she might need to migrate any conflicts to files both of you applied changes to.
Best regards, David
I have resolved the issue by cloning the repo in my local folder, adding the project to eclipse and changing the file committed.
Before that you have to add that person as a collaborator. So that he/she can clone your repo using the command below:
git clone "Path to the repository"
This is an old question but I'll like to say this to help others that might still be facing this same issue.
I also faced this issue with a friend. I already made him a collaborator but he couldn't push. What we did to solve it was to clone the repo using the ssh url instead. Then we set up authentication in git with ssh. And we were able push successfully.
If you already cloned the repo with the usual HTTPS url, you can change the remote origin url using the git remote set-url origin <url> command but url here will be the ssh url.

Un-fork GitHub project into new GitHub project not associated with the original [duplicate]

How can I make GitHub forget or disassociate that my repo was originally a fork of another project?
I forked a project in GitHub. I can now see "forked from whatever/whatever". The parent repository "whatever/whatever" is no longer maintained. I have been allowed to continue use of the code base of the original repository to create an independent repository.
Is there a way to detach my project from the original repository?
Update Jan 2022:
Use the GitHub chatbot-virtual-assistant at https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork
First answer:
You can contact github support and ask them to switch your repository to "normal mode".
On this page, "Commit was made in a fork" paragraph, it is explained that one has to go through support to switch. Therefore, it is likely that there is no way to do that by yourself (unless you destroy and recreate your repo which is explained before... if you do so be careful if you have tickets or a wiki attached to your project as they will be deleted!).
You could duplicate the forked repository to a new repository (without the fork dependency) from the GitHub UI, then remove the original forked one:
Sign in to GitHub
Select the + sign in the top right corner and select Import repository.
Import your forked repository. The new repository won't have the fork dependency.
Delete the original, forked repository in the repository settings.
NOTE: This approach will not preserve issues and pull requests.
Make sure you have all the important branches and tags on your local repo, delete the github repo, recreate the repository through usual means (no forking) and push the local repository back with git push --all. Note that if you have local branches that you don't want to publish, might be worth to create a temporary clean local clone for the operation.
However, this will also get rid of wiki and issues. As the wiki is in fact it's own repository, it can be handled similarly by cloning it and then recreating and pushing. The repo address is on wiki's Git Access page (git#github.com:user/repo.wiki.git).
This leaves issues. They can be exported through the API, but as far as I know, you can only create issues and comments with your person, so importing them perfectly is impossible.
So, if you need issues to be preserved, you should go through github support as Thomas Moulard suggests.
I got the similar problem, and ended up using this github help page to solve it. I didn't mind about the wiki and issues tracker as it was for my blog using a theme kindly developed by another user.
To detach a forked repo and use it as your own after several commits without losing the whole history:
git clone --bare git#github.com:user/forked_repo.git
Create a new empty reposity new-repository on the github website.
And push a mirrored version:
cd user.github.com.git/
git push --mirror git#github.com:user/new-repository.git
One can rename on github, the forked_repository with another name to keep it as backup and check updates if needed. Or simply delete it.
Renaming the new-repository to the original name does the job. As a side effect, your commits now appear in your history.
Log in to GitHub with your credentials.
Go to https://support.github.com/contact?tags=rr-forks&subject=Detach%20Fork&flow=detach_fork.
Choose "Detach", then enter the URL or repo name of the fork as your-user-name/repository-name, and answer the other questions of the virtual assistant.
You will get an email with a ticket number where you can check the status of your request. You will also be notified per email once your repo has been deforked.
Most repository settings will stay unchanged, including user permissions, stargazers, issues, PRs, discussions, etc.
Using the info from aurelien and Clayton, I was able to do this with the following:
$ git clone --bare https://github.com/my/forked_repo.git
<delete forked_repo on GitHub>
<recreate repo on GitHub using same name>
$ cd forked_repo.git
$ git push --mirror
Here's the documentation for git clone --bare:
Make a bare Git repository. That is, instead of creating <directory> and placing the administrative files in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.
Here's the documentation for git push --mirror:
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote.<remote>.mirror is set.
Note: like the other git based answers, this will not copy over issues that are not part of the git repo such as the wiki and issues. Per Tapio:
The wiki is a separate git repo and can be handled in a similar fashion per Tapio. The address is: git#github.com:user/repo.wiki.git.
Issues can be exported via the GitHub API but there are issues recreating them since they can only be created by your user, so imports will lose information.
This only applies to GitHub Enterprise, not on github.com
Logged in to an account that has admin privileges:
Go to the repository that you need to detach: https://<ghe url>/<org>/<repo>
Click on the “Site Admin” rocket on the top right corner
Click "Collaboration" on the top menu bar
Click on “Network” on the left pane
Click on “Make Root” in the Network Structure pane
Accept
This was tested on GitHub Enterprise 2.9
If you do not need any past commits (I didn't in my case), you can just:
fork the project
make a local copy of the fork (I used my IDE to do that)
delete the git folder from your local copy
commit the project as you normally would a new project.
You can just delete the fork from your github account after. Took me all of one minute and worked like a charm.

egit for eclipse: How do I put my existing project in the clone of my buddies repo?

My buddy gave me his git address for the project we are going to work on. In Eclipse using egit I cloned his branch.
So now in my Git view I have my own repository I created of an existing project. I want this existing project to be on my buddies branch so we can both check it out and have it in our repo.
Unfortunately I am using Windows to do this because we are developing a game and I do all of the art & animation in addition to programming. I would feel much more comfortable on the cmd line than using this plugin..
Any help is much appreciated!
The notion of repo and branch are quite different.
If you have a clone of our buddy's repo, you can work on a branch named like the one your buddy uses (by default 'master' if he hadn't created any other), and everything you will push will be added/merged to the remote branch in the remote repo.
For more on Egit, see this "Git with Eclipse (EGit) - Tutorial", and check if yuo can push at least one file, that your colleague will be able to pull from the remote repo and see directly in his branch.

Getting started with GitHub and Eclipse (spring source toolsuite 2.7.1)

I am new with both Git and GitHub so please bear with me.
I have an empty repository on GitHub with an automatically created branch (gh-pages), which, I understand, is supposed to be used with GitHub's pages functionality.
Now what I would like to do is to create and eclipse project from which I could commit/push to this repository.
What is confusing me that I can't see any option to create a remote branch on github. I suppose pushing my source to gh-pages won't be a good idea. BTW, I also don't understand why the GitHub pages is feature is implemented as a branch? Aren't branches supposed to be merged with each other at some point. Clearly it wouldn't make any sense to merge github pages into my project. Wouldn't it be better to have a folder within my project for this purpose.
I googled and found this link but being a git noob I am not sure if that's what I want to do. I would like to use Eclipse as my primary interface to git and github only falling back to command line or other interfaces when there is no other option.
OK I think I have figured it out. Basically, what you need is to define a remote ref that need not exist before hand.
Create a project
Team->Share it to a local repository
In the repository view (Window->Show View-> Git -> Repositories) select the local repository and right click on remotes
Select new remote (configure push). Type origin in the remote name. Press OK
Change URL. Copy/paste the ssh uri from github. Select ssh protocol (make sure you have ssh key defined in eclipse SSH preferences, and uploaded to github)
Now the last part is to add Ref mapping. Click on Add.. in ref mapping section of screen. And enter refs/heads/master in both local and remote branches.
Or may be the refs/heads/master on both side isn't a good idea :)
I see, cloning a github repo that doesn't have gh-pages branch is simpler as it automatically creates this remote fetch spec
Remote Fetch Specification +refs/heads/*:refs/remotes/origin/*
Maybe this is what I need to enter in the step 6 above
Ok as it turned out the original idea of "refs/heads/master in both local and remote branch" was correct. Pushing with this configuration is showing my changes in git hub correctly. The second option on the other hand is failing silently.
Branches typically are used in the way you described, but nothing says they must be used that way. This is just the way github chose to let you manage your page content, and it works quite well. It's kind of similar to hosting multiple repos on one SVN server.
As for creating new repos, if you create a repo in github and then clone it, you'll have an empty repo locally that already points to github with a remote named "origin". This is a convenient way to start out, since you don't have to mess with adding a remote yourself. At this point, your repo has no commits and no branches in it. When you make the first commit, it will automatically establish a branch named "master". I don't know how eclipse is set up by default, but from the command line with default settings, you have to explicitly push new branches to a remote or else they won't get pushed at all. I.e. making the first commit and doing git push will just fail with a message like "No refs in common and none specified; doing nothing". Instead, you have to git push origin master to tell it to establish the "master" branch in remote "origin" (aka github). Thereafter, just a git push will work fine.
Hope that clears up some of your confusion.