Header

Git CheatSheet

2020-12-09
 

Force pull #

git fetch
git reset --hard origin/master
shell

Assume unchanged #

git update-index --assume-unchanged exam.ple
shell

Upgrade git for windows #

git update-git-for-windows
shell

Delete tag #

git tag -d tagname
git push --delete origin tagname
shell

Remove submodule #

From https://stackoverflow.com/a/1260982/8810271

  1. Delete the relevant section from the .gitmodules file.
  2. Stage the .gitmodules changes: git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. Remove the submodule files from the working tree and index: git rm --cached path_to_submodule (no trailing slash).
  5. Remove the submodule's .git directory: rm -rf .git/modules/path_to_submodule
  6. Commit the changes: git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files: rm -rf path_to_submodule

Split repo #

Single File #

From https://stackoverflow.com/questions/39479154/how-can-i-split-a-single-file-from-a-git-repo-into-a-new-repo Use git fast-export.

First, you export the history of the file to a fast-import stream. Make sure you do this on the master branch.

cd oldrepo
git fast-export HEAD -- MyFile.ext >../myfile.fi
shell

Then you create a new repo and import.

cd ..
mkdir newrepo
cd newrepo
git init
git fast-import <../myfile.fi
git checkout
shell

Sub Directory #

git filter-branch -f --prune-empty --subdirectory-filter  path/to/module
shell

How to make file +x in Git on Windows? #

From https://stackoverflow.com/a/21694391/8810271

git update-index --chmod=+x foo.sh
sh
Leave your comments and reactions on GitHub