The command to create a git repository for an existing code base is the same as the one you use to create one for an empty project:
git init
Then you need to add your code to the repo:
git add .
Note this will add all of the files in the current directory. Most likely you don't want to do this. For example any .class
or .jar
files shouldn't be in the repo. To ignore these files, create a file named .gitignore
in your project directory and add the following lines:
*.class
*.jar
Be sure to add any other files that you don't want to include, for example, you can ignore an entire build
directory.
Finally, you can commit all your files to the git repository:
git commit
To upload your code to GitHub, you first need to create an empty repository on GitHub. Then you can add that repo as a remote to your local repo:
git remote add <ULR to your GitHub repo>
Finally, you push your code to GitHub:
git push origin master