Using Egit to Create a Repository
In this web page, the steps are given to create a Git
repository with the following properties:
- The repository will be able to hold multiple Eclipse
- The repository will also be stored remotely on github.com.
This web page assumes that the repo will be stored locally on a
Linux system, that the user's local user name is localname,
the user's github name is githubname, the name of the repo
is reponame both locally and on github, and the name of the
Eclipse project is projectname.
Create a Local Repository
This will create a local repo on your machine.
- Select File -> New -> Other -> Git -> Git
- Set Repository directory = /home/localname/git/reponame
Add an Eclipse Project to the Repository
Follow these steps to add any number of Eclipse projects to the
repo. The key is to locate the project in your Git repo directory.
- Select File -> New -> Java Project
- Set Project name = projectname
- Set Location = /home/localname/git/reponame/projectname
Add a .gitignore file
You should include a .gitignore file in your project so
that files that are created from your source files are not tracked.
This includes files created by the compiler (.class files)
and javadoc (.html files).
Create the Remote Repository
If you want to create a remote repository on github.com,
then you need to follow this step and the following step. You should
realize that that the default setup is to create a public
repository. If this is inappropriate, you will need to find/set up a
different Git server (or pay github.com for a private account).
- Logon to github.com
- Select New Repository
- Repository name = reponame
- Description = whatever
- DO NOT CHECK INITIALIZE
Setup the Local Repository to Push to and Pull from the
If you want to use a remote repository with your local
repository, then several properties of the local repository need to
be defined to enable push and pull operations. [These are
automatically defined when you clone a repository.]
- Part 1
- Select Window -> Show View -> Other -> Git ->
- You should see the Git Repositories "view" in the lower
left of your Eclipse window.
- Part 2
- right click reponame -> Properties
- Add Entry with Key = remote.origin.url and Value = https://github.com/githubname/reponame.git
[What github.com shows you for the https address of
your remote repo]
- Add Entry with Key = remote.origin.fetch and Value =
- Add Entry with Key = branch.master.merge and Value =
- Add Entry with Key = branch.master.remote and Value =
The First Commit
At this point, you should be able to do your first commit and
push (or just a commit if there is no remote repository).
- right click projectname -> Team -> Commit
- Enter a commit message, e.g., "First Commit".
- Check .classpath, .project, and .gitignore.
- Select Commit and Push (or Commit if there is no remote repo)
- If you selected Commit instead of Commit and Push, you can push by:
right click projectname -> Team -> Push to Upstream
right click projectname -> Team -> Remote -> Push