38

I am new to Git. I want to add an existing source code folder to Git, but based on the little documentation that I read, I guess files must be a Tar ball or tar.gz archive. I am also not finding a way to add an entire existing folder.

Is it not possible to add non-compressed files to Git repository along with the folder that contains the files?

3
  • Could you clarify: "The files must be a Tar ball or tar.gz archive", is this your requirement or is that what you think that git requires. Also, do you want to add the existing source code folder to an existing git repository or do you want to create a new git repository based on the existing source code? Commented Aug 2, 2011 at 11:40
  • In the documentation it says to add Tar balls. I guess, it is the default way. Commented Aug 2, 2011 at 17:36
  • possible duplicate of How to convert existing non-empty directory into a Git working directory and push files to a remote repository Commented Jun 10, 2013 at 8:54

3 Answers 3

48

It depends what you mean by adding a directory to a Git repository.

I get the feeling that you mean that you want to create a new project using an existing directory. In which case, you would need to go inside your directory and use git init. Here a quick guide I just found.

However, if you mean that you already have a Git project and wish to add a directory - the answer is simply to use git add path

Let us know if you need more information (such as setting up a remote, or using github.)

Sign up to request clarification or add additional context in comments.

1 Comment

No I mean the former. As I wrote above, I am using TortoiseGit as Git Front-end on Windows. I have created a repository where I want to add my source code folder.
23

No, you don't need it compressed. Git operates on the filesystem.

If you want to create a new repository from existing source, just cd into that directory and type: git init.

Add the current state of files to the index with git add . (note the trailing dot)

If you want to add existing code to an existing repository, you also need git add (and probably copy the files to where you repo is).

I suggest to take some time to actually learn and understand git before using, because doing so will save you a lot of trouble.

3 Comments

I am using TortoiseGit front-end. Could you please let me know how to import an existing folder to a Git repository?
I only used TortoiseGit for a very short time, but if I recall correctly, there is an add command in the right click menu (and all other git actions are there as well). So basically you do the same thing: copy your files into the repository, and use the add command on them. This tells git that you will want those files (at their current state) to be commited when you commit.
That is a very important point: LEARN git before use it in production.
0

In case if you are using Gitkraken then it is the most simplest method.

Steps:

  1. on Gitkraken- File -> Init Repo.
  2. Fill in the details.
  3. Click on Create and Init repo. and there you go your existing source code is uploaded on your github under you mentioned or created repo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.