MrMobster
MrMobster

Reputation: 1972

git: checking out a branch over existing files without overwriting them

We are moving a repository from another SCM to git. That in itself is not a problem, but I need to provide simple instructions to my users on how check can migrate their repository clones (bear in mind that most of my users are non-programmers and only have very basic terminal knowledge).

I was hoping that migration could be done like follows:

  1. Go to the folder with your checkout files
  2. Run git init
  3. Connect to the remote repository git remote add origin URL
  4. Synchronise the data git fetch
  5. Check out the files git checkout master

Now, my issue is with step 5, as git complains about "...untracked working tree files would be overwritten by checkout". Can I somehow force it to check out the branch without overwriting the files (e.g. treating any differences in files them as local changes applied post-checkout)? My current SCM will correctly detect which files are different would actually be overwritten and asks for user choice on what to do — I expected git to have similar functionality.

Basically, what I want is to tell git "you are now on latest master checkout, period. Don't do anything to the files". Is there a sane way of accomplishing it? Of course, I can always ask my users to make another clone and copy their old files over it, but I would like to avoid that if possible.

Upvotes: 0

Views: 94

Answers (1)

LeGEC
LeGEC

Reputation: 51830

Instead of git checkout master, you can try :

git reset origin/master

Then instruct them on how to inspect the diff.

Upvotes: 3

Related Questions