How can I associate local unversioned code to git remote repository?

I need to associate a clean unversioned code to an existing git remote repository.

I explain better my situation. My project is moved from svn to git. I have a svn local working copy with old code (nothing new to commit) that has to be syncronized with the new git repository. I could clone the repo but I should restore many ignored configuration files by hand and I would avoid it.

So I removed all .svn directories and I would track my code with the git remote repository.

Is there a way to do it?


I would commit your working directory to ensure that it exists in history before fetching. (ensure you are in the projects root folder)

git init
git add -A
git commit -m "my latest'

now we have it

git remote add origin url-to-your-remote
git fetch origin

now we have the history from the remote

git reset origin/master

now our current commit is the latest from the remote

git add -A
git commit -m "Committed my state"

now we use our current working directory as the snapshot for the next commit.

git push -u origin master

push up your changes and track the branch.

the key is the reset command with no --hard option. It keeps your working folder the same while pointing the branch to what you got from the remote.

Ok, I post the right answer for my question based on Adam Dymitruk and Eugene Sajine answers. Thanks everyone for the support :)

  • First of all, remove all .svn directories in working copy directory;
  • initialize new git repository in the working copy directory

    cd /path/to/my/project
    git init
  • add git remote repository and fetch it

    git remote add origin url-to-your-remote
    git fetch origin
  • reset working copy to remote repository

    git reset --hard origin/master

At the end local repository will be synchronized with remote repository.

If you really mean what you're saying then the sequence will be:

cd {your-project}
git init
git remote add {remote_name} {address}
git fetch {remote_name}

Then you can create a local branch from one of the branches that the remote has for example:

git branch master {remote_name}/master

and then you can add your code:

git add {files}


git add .
git commit


The OP specifies that the code in question is old and there is nothing to commit, therefore it seems that the whole situation is overcomplicated for no reason. OP just should clone the new repository and be done with it. Ignore configurations should be redone in accordance to the project policies (either .gitingore is stored in the repo or not and etc.)

Would the following work? I tried it on one of my projects and it worked.

1) Clone the git repository to a location different from the directory that contains the unversioned code.

2) Copy the .git folder from the directory created as a result of (1) to the directory that contains the unversioned code.

This effectively achieved for me what Adam Dymitruk steps in his answer above.

Need Your Help