Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhadeepakkumar14/d3f6fc1bb340b3ee04ac79ac4304b7d7 to your computer and use it in GitHub Desktop.
Save jhadeepakkumar14/d3f6fc1bb340b3ee04ac79ac4304b7d7 to your computer and use it in GitHub Desktop.
git-releted
Solution1:
Let's say we want to ignore build folder from all other branch except production branch . As we want to push build folder in production.
1) Dont include build in .gitignore . If you do that it will always be ignored for all branches .
2) Create a file exclude_from_public_viewing inside ./.git/info (This folder already exists) folder touch ./.git/info/exclude_from_public_viewing
3) Inside exclude_from_public_viewing write one line (As you are trying to ignore build for all the branches). !build
4)There's an existing file .git/info/exclude . We need to add following line in it.
build
We want to ignore build folder but hasn't added it in .gitignore . So how git will know what to ignore ? Answer is we are adding it to exclude file and conditionally passing that file to git config
5) Now we have to conditionally unignore build folder for production branch. to do that perform following
6) There is a existing file called ./.git/config we need to add following -
a) excludesfile = +info/exclude below [core]
[core]
excludesfile = +info/exclude
b) Create a new section in the end of ./.git/config as
[branch "production"]
excludesfile = +info/exclude_from_public_viewing
Solution 2
There is one smart alternate solution . Lets say you want to add build/ folder in production brunch and ignore it in all other branch.
1) Add it to your gitignore file.
2) In production brunch , while doing git add , force add build folder git add -f --all build/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment