0

I'm putting some Apache config files into a Git repository. The two servers should in theory have identical configurations. I've created a repository, committed the files and pushed the branch from the first server to the remote repository, and now I'm trying to check out the branch on the second server without touching any files.

The idea is that once I've checked out the branch, I can use git status to confirm that the files are identical on both servers (I've already manually spotted a minor difference). Any important differences can then be tracked in a separate branch. These are production servers, so I don't want to get anything wrong, even temporarily.

I'm used to using a GUI Git and I haven't used command line Git much. I only have shell access to the servers.

App-01 git show-branch -a:

* [master] Initial commit
 ! [origin/master] Initial commit
--
*+ [master] Initial commit

App-02 git show-branch -a:

[origin/master] Initial commit

I tried the solutions at switch git branch without files checkout (git symbolic-ref HEAD refs/heads/<otherbranch> then git reset) but looking back I think they presume an already existing local branch.

When I do git status on the second server, it shows all files as unstaged.

Is it possible to checkout a new branch without changing any local files? If so, what command(s) would do the trick?

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69

2 Answers2

0

Easily done:

Server A:

git init .
git add -A
git commit -m init
git checkout -b config-a
git remote add origin URL
git push origin config-a

Server B:

....the same for branch config-b....

Those commands will not change your files in any way.

Then on either machine:

git fetch
git diff origin/config-a origin/config-b

From here on, you can keep working like this. Obviously you want to avoid any wholesale checkout, merge, pull or rebase operation. But judicious use of cherry picking would probably not damage too much.

And you can safely edit files in some third repository so you can prepare larger changes by doing fast forward pulls.

AnoE
  • 8,048
  • 1
  • 21
  • 36
0

I just found a very simple way of doing this:

  1. Clone the Git repository into an empty directory. This will automatically check out all the files, which can then be ignored
  2. Move just the .git directory (and contents) into the directory where the old existing files are
  3. git status to confirm, it will show the few files that are different, if any

No existing files will be touched until further Git commands such as checkout, etc. are made.

CJ Dennis
  • 4,226
  • 2
  • 40
  • 69