Skip to content

Useful Git Information

fhogan edited this page Oct 19, 2017 · 3 revisions

Remove (unlink) a git package from repo.

  1. Delete the relevant section from the .gitmodules file. The section would look similar to:

[submodule "vendor"] path = vendor url = git://github.com/some-user/some-repo.git

  1. Stage the .gitmodules changes via command line using:git add .gitmodules. Delete the relevant section from .git/config, which will look like:

[submodule "vendor"] url = git://github.com/some-user/some-repo.git

  1. Run git rm --cached path/to/submodule. Don't include a trailing slash -- that will lead to an error.

  2. Run rm -rf .git/modules/submodule_name

  3. Commit the change:

  4. Delete the now untracked submodule files rm -rf path/to/submodule

Those steps will get you rid of that unwanted submodule.

Search and replace words within git repo.

To search and replace a word within a git repo, use:

git grep -lz '<word_to_search>' | xargs -0 perl -i'' -pE "s/<word_to_search>/<word_to_replace>/g"

Example:

git grep -lz 'RGRASP_BASE' | xargs -0 perl -i'' -pE "s/RGRASP_BASE/CODE_BASE/g"