Take the 2-minute tour ×

I don't know why this seems to be so unclear to me.

I have 2 repos, repo1 and repo2. In each repo are the branches: staging master and live

I think part of my problem is that I'm trying to get .gitignore working after already starting to use git (e.g. the repos were init'd before gitignore was populated correctly).

I've tried all the wonderful git-update-index --assume-unchanged file's and the neat git rm -r --cached .'s I could find, but I'm still not understanding because it still doesn't work.

I'd like a couple of specific config files and cache folders to be ignored on pull's and push's.


If I'm on repo1>staging and I push to repo2>staging, which .gitignore takes precedence? Or do they both get applied?


On a couple of attempts, I seemed to have gotten the config files to be ignored on push, but instead of just not sending over the changes to those files, it deleted them entirely out of the branch. Confusing.


If it would be smarter to start over (it's an option) in order to get .gitignore working, what would be a smart way to do so so as to not lose all the commits (they don't need to be accessible to the new repos, just accessible for FUBAR sake).



I have existing repos with a few files in them that I no longer want to be transferred on push's or pull's.

.gitignore is either not ignoring, or it is ignoring by way of deletion--which doesn't work because when I push, I need those config files to be there on the other end, and not deleted by the push.

I thought I'd be smart and start using git. It's excellently verbose, thusly confusing for newp.

I thought:

I could have a master and staging on production(prod), and a master and staging on dev(dev);

  • I would dev on the dev>staging branch, approve the gradients and other changes, then push to prod>staging;

  • On prod, git checkout staging and view to make sure it works;

  • All being OK, merge prod>staging prod>master, and checkout prod>master for the live site.

  • I'd then pull prod>master into dev>master, merge dev>master with dev>staging (or not, if they're the same), and start the cycle over again on dev>staging.

They are using different db's so as not to pollute prod while developing, and it's important to keep them separate.

share|improve this question
I'm not sure I understand what you're asking. Are you trying to add files to a git repository, but ignore them only on push and pull? Also, .gitignore files are committed to the repository after it is already initialized and as far as I know they are not populated automatically. Any files or directories specified in .gitignore will never be added to a commit and will therefore never be saved to the repository on commit. –  Mike Mar 8 '12 at 21:25
Additional note, you might find stackoverflow.com/questions/6147827/… helpful in setting up your repository to work as you desire. –  Mike Mar 8 '12 at 21:32
No, the files are already in there. I want to stop sending them on push's and pull's. In repo1 staging I have 1.cfg, I don't want it transferring; in repo1 staging: git rm --cached 1.cfg | .gitignore > 1.cfg | cp /tmp/1.cfg . | git commit | git push repo2 staging | cd repo2 | git checkout staging | cat 1.cfg > not found –  stormdrain Mar 8 '12 at 21:35
My understanding is .gitignore only ignores untracked files... once your files exist in the repository and are being tracked it doesn't work. You could do a pre-commit hook that reverts your config files before doing a commit. –  Mike Mar 8 '12 at 21:46
add comment

1 Answer

up vote 2 down vote accepted

.git/info/exclude If you wish the exclude patterns based on repositories , you may instead put them in a file in that specific repository named .git/info/exclude or core.excludesfile

.gitignore is used to add files which you don't want to be tracked. If the file is already being tracked and you want to add to .gitignore. run git rm --cached filename

share|improve this answer
If I had only scrolled to the bottom of help.github.com/ignore-files on any of the 8 visits I made there... Thanks! –  stormdrain Mar 9 '12 at 13:06
yaa..lot of docs out thr :) –  GhostRider Mar 9 '12 at 13:10
add comment

Your Answer


