Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 309
bato Avatar asked Oct 24 '12 15:10

bato


3 Answers

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.

like image 77
Adam Dymitruk Avatar answered Nov 13 '22 00:11

Adam Dymitruk


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.

like image 26
bato Avatar answered Nov 13 '22 02:11

bato


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}

or

git add .
git commit

UPDATE:

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.)

like image 44
Eugene Sajine Avatar answered Nov 13 '22 01:11

Eugene Sajine