Better way is use .gitattributes
, see
Merge Strategies
Show archive.org snapshot
Use Case
If we use an open source in our project, e.g. OpenMage Show archive.org snapshot , there are many files, e.g., README.md, install.php, etc., which are tracked but should be removed when we build the actual sites for development, staging, and production.
The method described here is the easiest that will remove the tracked files in our sites.
The git command that does the magic
Taken from Stackoverflow Show archive.org snapshot
git ls-files --ignored --exclude-standard -z | xargs -0 git rm --cached
I do not really know the details on what it does. Please do your own research.
Repositories
There are a minimum of 5 repositories:
- [remote open source repo] This is the repo of the open source, e.g. OpenMage/magento-lts Show archive.org snapshot .
- [remote personal open source repo] This is the forked repo of the open source, e.g. kiatng/magento-lts Show archive.org snapshot .
- [local open source repo] This is the open source in our local machine, it has 2 remotes:
-
origin
: point to [remote personal open source repo] -
upstream
: point to [remote open source repo]
-
- [remote project repo] This is the repo for our project in remote, can be in GitHub or BitBucket, or anywhere.
- [local project repo] This is our project in local machine. it has 2 remotes:
-
origin
: point to [remote project repo] -
upstream
: point to [remote personal open source repo]
-
Once we have above repos, we are ready for the following steps.
Detail Steps [Doesn't Work!]
- [local open source repo] Update the main branch by pulling from
upstream
[remote open source repo]. - [local open source repo]
- Doing this for the first time: based on the main branch, create a new branch
clean
. - In subsequent updates:
merge
main branch toclean
. Resolve conflicts if exist.
- Doing this for the first time: based on the main branch, create a new branch
- [local open source repo]
- Doing this for the first time: Open
.gitignore
and add all the unwanted files that should not be in the actual sites. - In subsequent updates:
.gitignore
should remain the same.
- Doing this for the first time: Open
- [local open source repo]
- Doing this for the first time: git remove the files listed in
.gitignore
in git bash:git ls-files --ignored --exclude-standard -z | xargs -0 git rm --cached
. Note that we can still see the removed files in our local disk, but there is no need to do anything here. These files will disappear when we switch to another branch and then switch back in to branchclean
. - In subsequent updates: unwanted files were not merged in
clean
.
- Doing this for the first time: git remove the files listed in
- [local open source repo] Commit changes to branch
clean
in git bash:git commit -am "Remove ignored files"
- [local open source repo] Push branch
clean
to remoteorigin
[remote personal open source repo], which is your personal fork of the open source repo. - [local project repo] Switch to
master
branch, or the main branch of your site. Git pull branchclean
from [remote personal open source repo]. Once it is pulled, the unwanted files are removed. - [local project repo] Now we can simply push branch
master
to remoteorigin
[remote project repo], we are now ready to deploy the updatedmaster
to our sites.
Sample of .gitignore
In branch clean
.
Note that the .gitignore
should only be applied when we have installed OpenMage in the site. Otherwise, there won't be any install script to install.
/app/etc/local.xml
/media/catalog
/dev/tests/functional/generated
/dev/tests/functional/vendor
/app/etc/local.xml.additional
/app/etc/local.xml.template
/downloader/
/skin/install/
/var/package/
/.all-contributorsrc
/.github
/.gitpod.yml
/.htaccess.sample
/.travis.yml
/CODE_OF_CONDUCT.md
/composer.json
/composer.lock
/index.php.sample
/install.php
/LICENSE_AFL.txt
/LICENSE.html
/LICENSE.txt
/php.ini.sample
/README.md
/RELEASE_NOTES.txt
/SECURITY.md
/EVENTS.md
Warning The above is only for reference, use at your own risk.