1

I have two Git branches, A and B. I am using Git to deploy changes from server 1 to server 2.

Branch A has a set number of files. Branch B has an extra directory (foo) with more files and a change to one of the files (bar) outside of the extra directory. I have branch A locally and a remote branch origin/A. The same for branch B and branch origin/B.

On server 1 if I check out branch A I see the original content in bar and I do not see the extra directory, foo. If I checkout branch B bar changes and the extra directory, foo appears.

Great. Server 1 works.

The problem is on server 2. If I checkout branch A bar changes but the extra directory, bar does not disappear as it does on server 1. On server 2 if I change to branch B bar also changes and the extra directory, foo is still present. So in summation, when I deploy to server 2 via git only changes within a file occur and addition/removal of files does not occur.

Is this normal behavior for git or should the files disappear when I checkout branch A?

Thanks

splunge
  • 73
  • 7
  • are all of your changes on server 1 committed and pushed? have you performed git pull on server 2? – Alex M Mar 31 '16 at 19:06
  • I do a fetch and checkout but when I do a pull after checking out branch B I get: $ git pull There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details git pull If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/ b – splunge Mar 31 '16 at 19:12
  • You used the word "deploy": in my experience, a lot of time when people say "deploy [on a server]" they are implying that the repository on the server is one created with `--bare` and that there's a post-receive hook that does something special on that server. However, you then talk as if you're logging in to the server and doing ordinary work-tree commands there, as if it is *not* a `--bare` repository. So, I'm not sure what your actual setup is. It might help if you showed the full sequence of commands that created these repositories and that you are using now. – torek Mar 31 '16 at 19:46
  • I don't have the exact commands that were used. I am deploying from my local machine to a shared dev server. On my local Windows box I am using GIT Extensions so I don't have the exact commands. The shared Windows dev box does not have GIT EXT installed so I am using git bash to run the commands. For the next deployment I will try to capture the commands/gui steps and add them to my post. – splunge Mar 31 '16 at 20:04

1 Answers1

1

The problem is on server 2. If I checkout branch A bar changes but the extra directory, bar do not disappear as it does on server 1

This is exactly how git behave, once you checkout branch the content of the working directory is updated with the content of the give branch.

This is the whole point behind branches. You can work on different content.

How else do you accept it to be? Every time you checkout different branch that it would checkout all the files in the whole repository?

Its only checking out the content of the given branch and updating the working directory.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I don't understand what you mean. Does git remove and add files based on different branches or just alter the content of files? I expect it to add and remove files based on the commit state of a particular branch. – splunge Mar 31 '16 at 19:10
  • Read this and once you done ill explain, it will give you a better picture. http://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location/34519716#34519716 – CodeWizard Mar 31 '16 at 19:11
  • Exactly, HEAD is what pointing to the current commit, every time you checkout branch yo change the HEAD and the content is changed (but not lost) – CodeWizard Mar 31 '16 at 19:23
  • What else do you still don't understand? – CodeWizard Mar 31 '16 at 19:24
  • What I don't understand is why file content changes but file existence does not change. Files remain in both branches on server 2 but on server 1 they appear or disappear whether I am on branch A or B. On both servers file contents change when I am on A vs B, which is what I expect. I think files should appear and disappear the same way on both servers. – splunge Mar 31 '16 at 19:26
  • In other words, if I change from branch A to B the content of files changes but the presence of files does not change on server 2. Server 1 works right in both aspects (file modification and file presence) while server 2 only works for file modification. – splunge Mar 31 '16 at 19:31
  • Exactly, branches are only local !!!. They will modify the local working directory only. Usually on server you use bare repo = no working directory – CodeWizard Mar 31 '16 at 19:35
  • On server 1: `$ git branch | b | * a` On server 2: $ git branch `a | master | * b | origin/b` – splunge Mar 31 '16 at 19:37
  • Feel free to ask anything you want to know, in here to help. – CodeWizard Mar 31 '16 at 19:37
  • What do you want to know? Each local repo has its own HEAD = different working directory, stage area and repo – CodeWizard Mar 31 '16 at 19:39
  • What I want to know exactly is what commands I need to run on server 2 to make it behave like server 1. I don't want to see only file content changes when I change branches on server 2, I also want to see files go and come back depending on which branch is checked out. – splunge Mar 31 '16 at 19:40
  • `git checkout branchA` (or any other branch that you have checked out), to find out which branch is it simply type: `git branch` and you will see astric next to the current branch – CodeWizard Mar 31 '16 at 19:43
  • Yes. That works. But what doesn't work is that files are not disappearing when I change branches on server 2. Only file contents are changing. When I do what you have written on server 1 files change and files disappear as expected. When I have a particular branch checked out, I want files to change and disappear/appear on any server, not just the 1st server. – splunge Mar 31 '16 at 19:47
  • If you agree that that should be happening then I think the reason that the files do not change their presence is because Windows has a lock on files and is not allowing them to disappear and appear. – splunge Mar 31 '16 at 19:50