[deprecated] How to remove tracked files in upstream before updating our sites

Updated . Posted . Visible to the public.

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:

  1. [remote open source repo] This is the repo of the open source, e.g. OpenMage/magento-lts Show archive.org snapshot .
  2. [remote personal open source repo] This is the forked repo of the open source, e.g. kiatng/magento-lts Show archive.org snapshot .
  3. [local open source repo] This is the open source in our local machine, it has 2 remotes:
    1. origin: point to [remote personal open source repo]
    2. upstream: point to [remote open source repo]
  4. [remote project repo] This is the repo for our project in remote, can be in GitHub or BitBucket, or anywhere.
  5. [local project repo] This is our project in local machine. it has 2 remotes:
    1. origin: point to [remote project repo]
    2. 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!]

  1. [local open source repo] Update the main branch by pulling from upstream [remote open source repo].
  2. [local open source repo]
    1. Doing this for the first time: based on the main branch, create a new branch clean.
    2. In subsequent updates: merge main branch to clean. Resolve conflicts if exist.
  3. [local open source repo]
    1. Doing this for the first time: Open .gitignore and add all the unwanted files that should not be in the actual sites.
    2. In subsequent updates: .gitignore should remain the same.
  4. [local open source repo]
    1. 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 branch clean.
    2. In subsequent updates: unwanted files were not merged in clean.
  5. [local open source repo] Commit changes to branch clean in git bash: git commit -am "Remove ignored files"
  6. [local open source repo] Push branch clean to remote origin [remote personal open source repo], which is your personal fork of the open source repo.
  7. [local project repo] Switch to master branch, or the main branch of your site. Git pull branch clean from [remote personal open source repo]. Once it is pulled, the unwanted files are removed.
  8. [local project repo] Now we can simply push branch master to remote origin [remote project repo], we are now ready to deploy the updated master 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.

kiatng
Last edit
kiatng
Posted by kiatng to Git (2020-09-03 03:25)