Skip to content

Instantly share code, notes, and snippets.

@btforsythe
Last active January 12, 2019 19:07
Show Gist options
  • Save btforsythe/89cc05543b6bfddcfe156c5b9cd09768 to your computer and use it in GitHub Desktop.
Save btforsythe/89cc05543b6bfddcfe156c5b9cd09768 to your computer and use it in GitHub Desktop.

Creating a GitHub repository from an existing Eclipse project (or simply an existing folder)

Create your Java project as usual in Eclipse, do your work, add files, etc. When you are ready to push to GitHub, take the following steps:

  • create a repository with the appropriate name in your GitHub account (do not initialize it with a README)

Then from Git Bash (remember to do git status often -- it will tell you what's going on!):

  • navigate to your project folder (if it is in the default location, the command would be cd default-workspace/<project-name>, where <project-name> is the name of your Eclipse project)
  • initialize your repository with the git init command
  • add your files to staging using git add <file-spec>, where <file-spec> is the file or folder you would like to add. Here are some examples:
To add... Use this add command
all of the files in the current directory (represented as '.') git add .
all of the files in the src directory git add src
only the README.md file git add README.md
only the src/main/java/MyClass.java file git add src/main/java/MyClass.java
  • commit your files to your local repository via git commit -m "<commit-message>", where <commit-message> is an appropriate message describing your commit
  • define the remote (GitHub) repository using git remote add origin <repository-url>, where <repository-url> is the url for the repository you created in GitHub.
  • set your upstream to the master branch on your GitHub repository and push your changes via git push --set-upstream origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment