user884786
user884786

Reputation: 33

How to add an Existing Java Project to Git repository

I am trying to add an existing Java project from a workspace to my git repository.

I'm using git version 1.8.3.2 on Linux.

I use this command:

git init/committed/remote origin/pushed

However, the src directory is only appearing as a greyed out empty folder.

How do I add a folder with subfolders to my github repository?

This is what it looks like. Notice 'src' is greyed out and un-clickable.

enter image description here

Upvotes: 3

Views: 9597

Answers (3)

simont
simont

Reputation: 72547

src and bin are git submodules. They're not browsable because they are only pointers to other git repositories - they're not really "folders".

To add everything in a directory and subdirectories to git in one command, you can use git add ., which recursively adds.

Section 6 of the Pro Git book explains what a submodule is.

Assuming you do not want submodules, you can fix your repository like this:

cd <project> # Go to the projects root
rm -rf .git  # Remove all git information (keeping your code). 
cd src       # and repeat for src and bin
rm -rf .git
cd ../bin
rm -rf .git
cd ..        # now, back in the projects root
git init     # Make a git repository
git add .    # Add everything to it
git commit -m 'Initial commit'
git remote add github <github-url>
git push -f github # Force push to github, to overwrite everything we had before. 

Note that this will destroy the git repos in src and bin!!

I'm pretty sure this is what you want to do.

Upvotes: 3

MaveRick
MaveRick

Reputation: 1191

To add *.* files and folders do it as follow:

  1. Navigate within your terminal/dos window to the the root folder of your project and use the command:

git init

git add .

git commit -m "This is my commit"

git push origin master

BTW: you can find more simplified details in the following tutorial: Import an existing, unversioned code project to an empty repository

Upvotes: 0

Related Questions