Is it possible to .gitignore on a per-remote basis? I want to be able to pull core updates from an open source project's public repo but push local changes from a (currently) .gitignored directory to my private git repo on a different remote. Is this possible?
Thanks!
EDIT: On further reflection, it looks like git submodules might be a good way to handle this.
http://git-scm.com/book/en/Git-Tools-Submodules
EDIT2: I've been using submodules all day and that solution appears perfect for what I wanted to accomplish.
Since the .gitignore
file is stored in the repository, it is versioned like
any other file. As such it can differ by branch, so you can make any changes to
your local copy that you like and commit those to your local branch(es).
The contents of the .gitignore
file do not affect retrieving contents of a
repository, so having local changes will not change the results that you get
when you pull from the projects public repo. But, you may need to manually
resolve conflicts in that file when the version from the public repository
changes.
Alternatively, you could just leave the .gitignore
file alone and use git
add -f
to add the files that you want to track locally. Once a file has been
added to the git repository it being ignored will have no effect. But if you
are regularly adding files to the ignored directory it would likely be a good
idea to modify the .gitignore
file so that git can remind you that there are
files which need to be added.
If you are going to be making other changes which you would like to send
upstream to the public project, those should be made on a branch without your
local changes to the .gitignore
file and the additions of those otherwise
ignored files. You can then merge those changes into your local branch with the
ignored files for your normal use.
I also had a similar problem where I worked with 2 remotes and needed to ignore different files over them.
This is what i did:
$ git fetch <public remote>
Merge all but exclude changes to the current .gitignore
$ git merge --no-ff --no-commit <public remote>/master
$ git checkout master path/to/.gitignore
$ git commit -m "Merged ... into ... excluding the .gitignore"
This way I pull the changes from a remote and keep my existing .gitignore file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With