Push eclipse project to GitHub with EGit - eclipse

I am successfully pushing my project to GitHub using EGit. My repository is called HelloWorld. My project in eclipse is also called HelloWorld. My problem is when i push the project it is upload the project under the folder HelloWorld. So the result is the repository HelloWorld then the folder HelloWorld and the the src folder. To be more understandable here is the link of the project. I want under the repository HelloWorld to have the src folder. How can I achieve that?

The key lies in when you create the project in eclipse.
First step, you create the Java project in eclipse. Right click on the project and choose Team > Share>Git.
In the Configure Git Repository dialog, ensure that you select the option to create the Repository in the parent folder of the project..
Then you can push to github.
N.B: Eclipse will give you a warning about putting git repositories in your workspace. So when you create your project, set your project directory outside the default workspace.

Simple Steps:
-Open Eclipse.
Select Project which you want to push on github->rightclick.
select Team->share Project->Git->Create repository->finish.(it will ask to login in Git account(popup).
Right click again to Project->Team->commit.
you are done

I use these Simple Steps when I already have committed locally a new project:
Open github.com and sign in and create a new repository.
Copy URL of the new repository.
Open Eclipse.
Select Project which you want to push on github->rightclick.
select Team->share Project->Git-> "push branch '' ...".
Follow the wizard until it finishes.

I have the same issue and solved it by reading this post, while solving it, I hitted a problem: auth failed.
And I finally solved it by using a ssh key way to authorize myself. I found the EGit offical guide very useful and I configured the ssh way successfully by refer to the Eclipse SSH Configuration section in the link provided.
Hope it helps.

If you ever face an authentication issue in any IDE - Eclipse, sts, etc. Simply while creating a remote repository select ssh protocol it won't ask you any username or password. (But will create a file ed25519 on your system which will be having an ssh key). Now you can push or do other activities using IDE without having any authentication issues.
In case of Git bash use command $ssh-keygen (ask for file give proper file path)
suppose you give name as y.pub.
Run the command $cat y.pub
copy the ssh key(starting something as ssh-rsa...) and paste in GitHub(opened in browser your remote repository)
now type command $ssh -t git#github.com
If you get an error while using the above command changed the command to
$ssh-keygen -t ed25519 -c "your userid"
then open the file by using $cat ed25519.pub file
copy the ssh key & paste into Github. Now you are authenticated to perform the various operations.
The other option if you want to use https only is to generate pat(personal access token).go to github-go to settings-go to developer settings-go to personal access token.If you aready had token delete it else click on generate new token.Give anything in note.Click on repo (you can select multiple options too) click generate token.Copy the token and now in your ide instead of password use the token.I hope it will solve your problem.

Related

Is it possible to create github repository for my project in Visual Studio Code?

Is it possible to create github repository for my project in Visual Studio Code,
and commit all the files?
I have not found a single example where a repository is created from VSCode.
Now, there is also a "Publish to Github" button in the "Source Control" part, when there is no git repository, to directly create a repository on github.
If you click on it, by default, VSCode propose (in the main bar) to create a private or a public repository with the project's folder name.
Just make a new file in VS Code. Local file created in VSCode
Go to Source Control. You will have an option to Initialize Repository, which inturn creates a repo in Github.
Note : You need to connect to your github account before hand.
There is documentation on this page on how to initialize a repository in vsCode: https://code.visualstudio.com/docs/editor/versioncontrol
EDIT:
Another link that should be helpful: https://code.visualstudio.com/docs/introvideos/versioncontrol
Use GitHub API to create repo. Outside of the API, there's no way to create a repo on GitHub via the command line.
curl -u 'username' https://api.github.com/user/repos -d '{"name":"projectname","description":"project desc"}'
git remote add origin git#github.com:nyeates/projectname.git
As far as I can tell, it's currently not possible with a default installation of VS Code. But you can make it work like this:
Add the REST API client by Huachao Mao to VS Code (others may work, haven't tested).
Create a personal access token in GitHub.
Create a new temporary file and enter the following text:
curl -u 'myGitHubUsername:myToken' "https://api.github.com/user/repos" -d '{"name":"MyNewRepo","description":"Repo Description"}'
Then select the line, press F1, look for "REST" in the search field and run the command "Rest Client: Send request"
After a short while you should be able to add the new remote repo using onboard tools.
Obviously, this is too elaborate for a one-time use. But once it's all set up, it's quite easy to create new repos or interact with the GitHub API in other ways.

Integrating Eclipse and GitHub

I am in need of help in trying to setup Eclipse so that I can push my code onto my GitHub account. I've searched online and the tutorials I have found are either outdated or don't work for me.
I already have a project on Eclipse. How would I put that code onto GitHub? Would someone please add detailed instructions please. Any help is appreciated.
EDIT
As soon as I posted this question, and fiddling around with the settings I managed to get it to work! What a coincidence...
The only problem I have now is how do I set it up so that when I commit it will only select the files in the project folder? Right now it is showing all 600 files in the Package Explorer.
Alright, there are several ways of doing this. I found this to be the easiest way:
First, set up SSH2 configurations. Go to Windows->Preferences->General->Network Connections->SSH2->Key Management and Generate RSA Key. Save Key
Copy that key. You will need to go to your GitHub account settings and add the new SSH key to your account.
Now, you need to install eGit:
Next, you want to add the Git Repositories view:
Create a new Git Repository. I have already created a repository called Java. I will refer to that repo for the rest of the explanation.
After you create your repository, it should show up in the Git Repositories view. Now to add your project to the repository, right click on your project and select Team->Share Project.
Select the repository you just created. You can also use CTRL+ to select multiple projects and place them in one repository.
Now go back to your Git Repositories view. Go to Remotes . Right click and select Create Remote.
Select Change... and enter the SSH link for your Repository on GitHub.
For connection, select SSH. Then press Finish.
For Rev-mapping, select Advanced....
For Source Ref select refs/heads/master. And then press Add Spec, then select Save specifications in 'origin' configuration. Then press finish.
That's pretty much it. You can commit changes by right clicking your project - >Team->Commit...`
Push new commits to GitHub:
This is a really good explanation on how to set up Eclipse pull requests.
The current branch is not configured for pull No value for key branch.master.merge found in configuration

Netbeans fails to access GitHub using SSH key

My (newest) Netbeans (NetBeans IDE 7.3 (Build 201302132200)) seems to be failing completely, when I'm trying to access my own GitHub repo using SSH. It works without problems with HTTP URLs.
Since I've imported an existing local copy of GitHub repository (New > PHP Project with existing sources), created once with TortoiseGit, there were remote settings saved in local copy meta-data (probably in .git folder). So Netbeans offers option Select Configured Git Repository Location in Push to Remote Repository window. But is unsuccessful at that.
Tried following:
When I'm using SSH URL (git#github.com:user/reponame.git) and Password option, with account pass, Netbeans tries to connect GitHub (remote) and after circa 5 seconds throws error Cannot connect to the remote repository at git#github.com:user/reponame.git.
When using SSH URL with Private/Public Key option, Netbeans throws exactly the same error immediately, so I assume, that for some reason it doesn't even tries to connect GitHub.
What is even more strange (?), Netbeans is not asking for private key's passpharse. I've set it, but did not entered it to Netbeans deliberately, to test connection process. I was more than sure, that Netbeans will ask me to provide this passpharse, as it shouldn't be able to use private key without it. To my surprise, it hasn't asked for it and instead it thrown an error saying, that it can't connect GitHub. Of course, that was only a test. After entering correct passpharse, I'm getting exactly the same effects.
I've copied my repo's URL directly from GitHub website, without any modifications. It seems, that I can only use HTTP URL (https://github.com/user/reponame.git). This works and assures me that all items (URL, user, reponame, password, finally Internet connection) are OK. But, it seems, that Netbeans fails completely on SSH URL.
Above happens always, no matter if I select Select Configured Git Repository Location or Specify Git Repository Location in Push to Remote Repository window. No matter, what I'll do I can't access my repository via SSH in Netbeans and using HTTP is the only option.
I have created my private-public key pair using puttygen.exe from PuTTY's website. I saved private key in Netbeans installation directory and added public key to GitHub's SSH Settings page. I used step-by-step guide I normally use with TortoiseGit.
I don't know what else I could miss out or I'm doing wrong? Any idea?
For the record:
When generating keys with PuTTYgen, it's recommended for compatibility to export it as an OpenSSH key. This can be achieved by accesing Conversions > Export OpenSSH key menu.
After series of many tests, I found out that Netbeans:
Does not work to well with existing local copies of GitHub (or any other git) remote repositories.
Does not work at all with SSH keys generated by puttygen.
As for first, I had to remove entire folder cloned with TortoiseGit and clone the same repository using Netbeans-bundled tools (Team > Git > Clone). The same goes for Subversion (look here) -- so the general rule of thumb says, that when you're switching from another Git or SVN client to Netbeans, you should do a full, clean clone (or checkout) of remote repository as attempts to re-use existing copy will most likely fail.
As for second, follow instructions given in this GitHub article and use ssh-keygen (either from your local installation of Git for Windows, in case of Windows or from any other source) instead of puttygen -- SSH keys generated by it can't be used in Netbeans for setting up password-less login to GitHub.
As I wrote, I've been using TortoiseGit previously, which accepts and works well with puttygen keys, so it wasn't to obvious for me, that source of the problem is here.
After fixing this two problems (getting clean clone and generating correct keys), ale problems expressed in my question were gone and Netbeans works with GitHub repositories like a charm.
My solution was to use a the ssh-keygen with the PEM option:
ssh-keygen -t rsa -b 4096 -m PEM -C my#mail.xy
Netbeans 12 use JGit for the Git-tool and this supports only special kinds of ssh keys?

Can't push using EGit and Bitbucket

I've been trying to start a project using EGit with Bitbucket but I can't push the project to the repository in the server.
These are the steps I've followed (I'll try to be very specific so other people can use it as a tutorial mode; even though it's not working for me it might work for others):
1) I installed Git on Ubuntu 12.10 using this tutorial
2) Followed this tutorial for GitHub.
Start a new C++ project in Eclipse
Under Window > Preferences > General > Network Connection > SSH2 > Key Management tab, I generated a new RSA key and added it to the list of deployment keys of my repository on Bitbucket.
Right click on the eclipse project: Team > Share project ; Team > Add to index ; Team > Commit
Window > Show View > Other > Git > Git Repositories
Right click on Remotes > Create Remote > Checked "Configure push" and typed my project's name
Add Push URL: ssh://git#bitbucket.org/myuser/myrepository.git, Protocol: ssh; port: blank; user: git; password: blank
Advanced button under Ref mappings and selected the "master" version. If this step works, it means that the RSA key is configured in Bitbucket and EGit properly. Otherwise it will show a connection error.
Everything is done. However, when I press "Push" I get the following error:
ssh://git#bitbucket.org/myuser/myrepository.git: push not permitted
I've tried every configuration possible: switched to a new work space, updated Eclipse, created new repositories, re-installed Git... Any ideas?
Alright, I've finally found a way to work with it.
It's just changing the authentication mode. If the HTTPS link is used, instead of using the SSH link, everything works perfectly. It seems that SSH works just in a read-only mode.
Of course the authentication method is different: you have to type the password and the SSH keys stored in Bitbucket are no longer necessary.
For those who are having problems with EGit, I recommend following eugener's way to automatically configure EGit. Then you just have to select HTTPS as authentication mode to push the stored commits.
There is much simpler way of configuring remote Git repos in Eclipse:
Create an empty repo on BitBicket
Copy repo's URL
Clone repo to your machine using "Git Repositories" view.
Share your project into newly cloned repo.
Since a repo was cloned - remote settings were configured automatically. This means you will be able to push immediately
It might be a user name misconfiguration in .gitconfig.
Probably related, I fixed "auth fail" problems by following the instructions on:
http://wangpidong.blogspot.com.es/2012/05/how-to-use-bitbucket-with-egit-in.html
Got it from:
Configuring egit with BitBucket
In this specific case I agree with resolution from Olivier J.'s comment under original question.
But I have had similar problem and it was caused by something else. I resolved it and here is what happened:
I have been using some private repository at Bitbucket (A) with some user account and some public key (X) to access it. I have had key X loaded in my pageant Putty key chain.
Then I created a new public repository (B), also at Bitbucket with a different user account and another public key (Y). I added this key to pageant too.
When I tried to access repository B apparently public key X and not Y was used, because ..for SSH client both connections are the same - same user (git) at the same host (bitbucket.org)! And key X was used first because ..it was loaded earier? Or maybe because its name was alphabetically first? I am not sure but the result was that...
Read-only access for B using X was granted because the repository was public and any valid Bitbucket user key was enough to gain this kind of access!
..but writing (pushing) required key Y, which was not used by SSH.
So the general tip is: to resolve strange read-only git via SSH access errors check carefully which private key is actually used by SSH.
I resolved this problem by loading only one key - X or Y - in pageant at a time but I would love to do it a smarter way - please let me know in comments if you know how!
Using Bitbucket I do it this way:
create a repository in bitbucket
clone the empty repository using the https url
connect the project in eclipse to the repository using the Team -> Share option and select the location where you cloned the repo
index (stage) your project files
commit and push

How to set up Netbeans, Mercurial and BitBucket with SSH

I set up Mercurial (actually TortoiseHg) to work so that Netbeans could interact with BitBucket. I set it up with HTTPS, but now I'm trying to use SSH instead. I'm not having much success. Here are the steps I took:
First, I opened PuTTYgen and generated an SSH2-RSA key. I wrote my email - the same one I used to register on BB, I don't know if that matters - as the Key comment. Anyway, I uploaded the public key to BitBucket and it accepted it.
Then I created a private key and added it with pageant, as this page instructs. After that I made a command from the command line to verify it worked:
hg clone ssh://hg#bitbucket.org/myaccount/myrepo
It worked - cloned the entire repo to my computer. But then I went over to Netbeans and right-clicked on my project and went to Mercurial > Properties.... I filled out the box like this:
default-push: ssh://hg#bitbucket.org/myaccount/myrepo
default-pull: ssh://hg#bitbucket.org/myaccount/myrepo
username: My Name <my#email.com>
I tried to push/pull my repo, but it didn't do anything. I'm using Netbeans 7.0.1. How do I fix this?
You can setup your repo as https. I already tried and it works.
default-push: https://hg#bitbucket.org/myaccount/myrepo
default-pull: https://hg#bitbucket.org/myaccount/myrepo
username: My Name <my#email.com>
You will need to setup the SSH link in the hgrc file for the repository or the one that is used by Netbeans.
Details can be seen here, how it can be setup: http://wiki.netbeans.org/FaqHgSSH