views:

40

answers:

3

I have a remote that is the same, or similar, to the rails project in my current directory. To sync the two, I do

git init
git remote add origin blah@blah
git pull

The problem is that some of the files I had in my working copy were added (ie not in the remote), so when I do

git status 

it should show a bunch of untracked files. Instead I see the files from the repo that are out of date.
Why didn't it ask me to resolve conflicts in these files? And where are my old files?

A: 

If you have a local repo (with its working directory), you shouldn't need to 'git init' anything.

git remote add origin blah@blah
git pull

should be enough.

If you have made a git init, that should be in an empty repository, where you then imported the master content of 'origin'.


I didn't have a local repo, just the local files.

Then you need to add them first (see r-mercado's answer).

From the git pull man page:

Warning: Running git pull (actually, the underlying git merge) with uncommitted changes is discouraged: while possible, it leaves you in a state that is hard to back out of in the case of a conflict.

VonC
I didn't have a local repo, just the local files.
tesmar
A: 

What if, after the commands you did above, you try doing this?

git checkout blah
git pull origin blah

I'm still learning git, so I'm not positive, but just a guess. (Might need to replace blah with blah@blah in the commands above too.)

Matt Huggins
+2  A: 

The merge implicit in "git pull" must have overwritten local files that were not committed.

I would suggest this sequence:

git init
git add .
git commit -m"local"
git remote add origin blah@blah
git fetch origin

At this point, observe the repository with "gitk --all"

Merge with

git merge remotes/origin/master

This should let you know of conflicts, if any. And local files won't be overwritten.

Makis