I have code in Eclipse that I'd like to upload to GitHub but so far I can't figure out how. It says "create a repository" but that looks more like a folder that holds your projects and I'm not sure how to upload my code to it. Apologies for the seemingly dumb question. Also, how does one delete repositories? Didn't see a way to do that either.
-
Does your eclipse project use git as an SCM? If not, you need to start here...– fgeJul 9, 2013 at 15:41
-
2Learn git first just with a local repository (git init). Then github makes much more sense.– Thorbjørn Ravn AndersenJul 9, 2013 at 15:48
-
In case you still need it, in order to delete a repository, open it in github, click on the 'Settings' tab and scroll to the bottom, where you will find the 'Delete repository' option. :)– DomJun 17, 2018 at 17:45
6 Answers
While the EGit plugin for Eclipse is a good option, an even better one would be to learn to use git bash -- i.e., git from the command line. It isn't terribly difficult to learn the very basics of git, and it is often very beneficial to understand some basic operations before relying on a GUI to do it for you. But to answer your question:
First things first, download git from http://git-scm.com/. Then go to http://github.com/ and create an account and repository.
On your machine, first you will need to navigate to the project folder using git bash. When you get there you do:
git init
which initiates a new git repository in that directory.
When you've done that, you need to register that new repo with a remote (where you'll upload -- push -- your files to), which in this case will be github. This assumes you have already created a github repository. You'll get the correct URL from your repo in GitHub.
git remote add origin https://github.com/[username]/[reponame].git
You need to add you existing files to your local commit:
git add . # this adds all the files
Then you need to make an initial commit, so you do:
git commit -a -m "Initial commit" # this stages your files locally for commit.
# they haven't actually been pushed yet
Now you've created a commit in your local repo, but not in the remote one. To put it on the remote, you do the second line you posted:
git push -u origin --all
-
10This answer is very good! The only problem that I had was that before
git commit -a -m "Initial commit"
I needed to first do agit pull https://github.com/[username]/[reponame].git
Not sure if the problem was something I did wrong or not, but it worked after that.– The DudeJul 7, 2014 at 4:17 -
1I believe you will also need to click 'share project -> git -> repo' in eclipse– rednoyzOct 10, 2016 at 18:50
-
@Jokab but my local eclipse workspace in ~2 gb, how to stop it from uploading .metadata and other unnecessary files. Add all adds everything. Nov 20, 2016 at 14:14
-
-
2@TheDude You'll have to pull first if the repo isn't new. If it's a brand new (with no files) git repo then the above will work. Mar 11, 2017 at 13:04
Here is a step by step video of uploading eclipse projects to github
https://www.youtube.com/watch?v=BH4OqYHoHC0
Adding the Steps here.
Right click on your eclipse project -> Team -> Share project
Choose git from the list shown; check the box asking create or use repository -> click on create repository and click finish. - This will create a local git repo. (Assuming you already have git installed )
Right click on project -> Team -> Commit - Select only the files you want to commit and click on Commit. - Now the files are committed to your local repo.
Go to git repositories view in eclipse ( or Team -> Show in repositories View)
Expand the git repo of your project and Right click on Remotes -> Create Remote
Remote name will appear as origin, select 'Configure Push' Option and click ok
In the next dialog, click on change next to URI textbox and give your git url, username, password and click on 'Save and Push'. This configures git Push.
For configuring Fetch, go to Git Repositories -> Remote -> Configure Fetch -> Add -> Master Branch -> Next -> Finish -> Save and Fetch
For configuring Master Branch, Branch -> Local -> Master Branch -> Right click and configure branch -> Remote: origin and Upstream Branch : refs/heads/master -> click ok
On refreshing your repo, you will be able to see the files you committed and you can do push and pull from repo.
-
1
For eclipse i think EGIT is the best option. This guide http://rogerdudler.github.io/git-guide/index.html will help you understand git quick.
Many of these answers mention how to share the project on Git, which is easy, you just share the code on git, but one thing to take note of is that there is no apparent "project file" that the end user can double click on. Instead you have to use Import->General->Existing project and select the whole folder
Jokab's answer helped me a lot but in my case I could not push to github until I logged in my github account to my git bash so i ran the following commands
git config credential.helper store
then
git push http://github.com/[user name]/[repo name].git
After the second command a GUI window appeared, I provided my login credentials and it worked for me.