简体   繁体   中英

How to ignore a file when commits to a certain remote repository in git?

I have two remote repositories public and private on Git, and I have one local repository local on my own computer. From time to time, I need to merge my local repository with the most recent commits from both public and private like this:

$ git pull  # pull from the private repo
$ git pull public main  # pull from the public repo
$ git commit -a -m 'Merged public and private'

Then push back to the two remote ones.

$ git push # push to the private repo
$ git push public # push to the public repo

The problem is, there are some .txt files (not all txt) in my local repository that I want to push to the private repository but not to the public one. The way I am doing it is: first run git push to push to the private repo, then delete these files manually from my local repo. Next push to the public repo using git push public . Finally add them back to my local repository. Is there a better way to do it?

Use submodules: include the "private" files in submodules and add the submodule only to the private repository.

Each clone of a repository contains everything, there is no way to "prevent" something to be cloned.

As such, if you are pushing to what are essentially two mirrors of the same devspace, you'll have logically separate private from public.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM