0

I have a repository with a Laravel App I'm working on which has master and gh-pages branches.

When I do

git checkout gh-pages

Everything works but two directories 'app' and 'vendor' from the master branch show up. In the gh-pages branch I added them both to .gitignore just to make sure they don't get pushed up to the gh-pages remote branch. But then I decided to try deleting the vendor directory. When I switched back to the master branch the vendor directory was gone so I had to run composer install to get it back.

Then I tried cloning the repository over again, fetching the gh-pages branch and the same problem occurs.

ignoring them in the gh-pages branch works but they don't belong there so I'm confused as to why they are there. These are the only two directories that appear in both branches.

You can see looking at the repo on github https://github.com/isimmons/office-twit that these directories are not there so I don't understand why they are there in my local cloned repo.

UPDATE: Starting with a clean clone of the repo here is a complete listing of the cli output. Something happened that made the /app directory go away in gh-pages branch but the problem is still there with the /vendor directory.

C:\Users\lotus\projects
λ git clone git@github.com:isimmons/office-twit.git
Cloning into 'office-twit'...
remote: Counting objects: 470, done.
remote: Compressing objects: 100% (254/254), done.
rRemote: Total 470 (delta 190), reused 458 (delta 178)
Receiving objects: 100% (470/470), 946.23 KiB | 460.00 KiB/s, done.
Resolving deltas: 100% (190/190), done.

C:\Users\lotus\projects
λ cd office-twit\

C:\Users\lotus\projects\office-twit (master)
λ ls
app      bootstrap      composer.lock    phpunit.xml  readme.md   upgrade.md
artisan  composer.json  CONTRIBUTING.md  public       server.php

C:\Users\lotus\projects\office-twit (master)
λ git remote
origin

C:\Users\lotus\projects\office-twit (master)
λ git branch
* master

Everything is good at this point. Double checked to make sure all I have is 'origin' remote with 'master' branch and the /vendor directory is missing as it should be.

Before pulling in the gh-pages branch I do a 'composer update' which adds the /vendor directory.

C:\Users\lotus\projects\office-twit (master)
λ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing intouch/newrelic (dev-master aca23cc)
    Loading from cache

  - Installing symfony/translation (2.4.x-dev 0919e0f)
    Loading from cache

    . . . many more packages install . . .

Generating autoload files
Generating optimized class loader

Listing the contents of the directory I see /vendor as I should at this point, and git status shows a clean directory as it should because /vendor is in the .gitignore file.

C:\Users\lotus\projects\office-twit (master)
λ ls
app      bootstrap      composer.lock    phpunit.xml  readme.md   upgrade.md
artisan  composer.json  CONTRIBUTING.md  public       server.php  vendor

C:\Users\lotus\projects\office-twit (master)
λ git status
# On branch master
nothing to commit, working directory clean

Next I checkout and track the gh-pages branch so what I have locally should be identical to what is on the remote (origin).

C:\Users\lotus\projects\office-twit (master)
λ git checkout -b gh-pages origin/gh-pages
Branch gh-pages set up to track remote branch gh-pages from origin.
Switched to a new branch 'gh-pages'

As you can see somehow the /vendor directory shows up in the gh-pages directory though on the remote viewing gh-pages branch at https://github.com/isimmons/office-twit/tree/gh-pages the directory does not exist. So this is happening locally.

C:\Users\lotus\projects\office-twit (gh-pages)
λ ls
assets  index.html  README.md  vendor

C:\Users\lotus\projects\office-twit (gh-pages)
λ git status
# On branch gh-pages
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       vendor/
nothing added to commit but untracked files present (use "git add" to track)

I don't want to push gh-pages at this point because /vendor doesn't belong there and while adding /vendor to .gitignore will keep it from being tracked, it shouldn't be there at all.

If I delete /vendor while in the gh-pages branch, then git status shows a clean working directory but then when I change back to the master branch /vendor has been deleted there too.

C:\Users\lotus\projects\office-twit (gh-pages)
λ rm -rf vendor

C:\Users\lotus\projects\office-twit (gh-pages)
λ git status
# On branch gh-pages
nothing to commit, working directory clean

C:\Users\lotus\projects\office-twit (gh-pages)
λ git checkout master
Switched to branch 'master'

C:\Users\lotus\projects\office-twit (master)
λ ls
app      bootstrap      composer.lock    phpunit.xml  readme.md   upgrade.md
artisan  composer.json  CONTRIBUTING.md  public       server.php

LAST UPDATE: I just figured out why the /app directory was there before. When I have the local repo opened for editing in SublimeText even if the master branch is clean, then change to the gh-pages branch, /app re-appears in that branch. This wasn't happening above because I was strictly using the cli. So the solution to that part of the problem is to completely close the /app directory before switching branches.

isimmons
  • 2,016
  • 2
  • 20
  • 32
  • I find it oddly complicated that GitHub wants a `gh-pages` branch, instead of a `gh-pages` folder. With a folder, it's much easier for the demo of a project use files from master, without having to keep the two branches in sync all the time. There's a highly-voted question about [mirroring gh-pages to master](http://stackoverflow.com/questions/5807459/github-mirroring-gh-pages-to-master). – Dan Dascalescu Jun 04 '15 at 05:27

1 Answers1

1

In gh-pages you are ignoring /app and /vendor. In master you are ignoring only /vendor, /app is actually in your branch.

Whatever you have in your local clone, if it's not in the repository, then it didn't get there from the repository, it must have got there some other way.

It seems you're just getting mixed up, that's all. If you have a clean clone, and then switch between branches, everything should work as expected: only master will have the app dir, and none will have the vendor dir.

Note that when your working dir is clean (no changes and no staged changes), and you switch from master to gh-pages, Git will correctly remove the /app directory.

UPDATE

When you switch from master to gh-pages, Git will correctly NOT remove vendor, which is marked to be ignored. The master branch doesn't track this directory, and removing it automatically would be dangerous. So it doesn't remove it, and this is normal. It seems that adding /vendor back to .gitignore would solve all your problems.

janos
  • 120,954
  • 29
  • 226
  • 236
  • Right, master is supposed to have /app. Locally it also gets /vendor from doing composer install. There is nothing wrong with the master branch. It's just when I checkout gh-pages locally I can watch the files change in my editor (sublimetext) and all of them will change except /app and /vendor stay there. I did a ls from command line and they are listed there too. I'll try a new clone in the morning and see what happens. Maybe I messed something up and will see it then. – isimmons Dec 15 '13 at 07:52
  • No need for a new clone. When your working dir is clean (no changes and no staged changes), and you switch from master to gh-pages, Git will remove the /app directory. – janos Dec 15 '13 at 08:02
  • I updated the question to show all the output from cli. This time not even opening the repo in a editor and starting with a clean clone to make sure SublimeText wasn't doing something weird. Maybe you can see something I'm doing wrong when cloning and checking out branches. – isimmons Dec 15 '13 at 17:39
  • See my updated answer. I think it made more sense when you had `/vendor` in `.gitignore`. – janos Dec 15 '13 at 17:59
  • Seems more correct to me that git would just not include /vendor in the gh-pages branch. But your explanation makes sense. I guess for future proofing I could just make .gitignore in the gh-pages branch identical to the one in the master branch. If I were to add ruby gems or npm packages later for some reason I would need to add them to both .gitignore files too right? Still not sure what was going on with /app since it was never in the master .gitignore file but it's gone now so I won't worry about it. BTW thanks for helping me understand this. – isimmons Dec 15 '13 at 18:22
  • Yeah, usually `.gitignore` is the same in all branches, things would get confusing otherwise. – janos Dec 15 '13 at 19:02