Skip to content

Instantly share code, notes, and snippets.

@InKolev
Last active March 10, 2017 09:26
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 InKolev/519c943258d0ea7acb2aef0531dc419c to your computer and use it in GitHub Desktop.
Save InKolev/519c943258d0ea7acb2aef0531dc419c to your computer and use it in GitHub Desktop.

Unstage all files staged for commit

  • Command
git reset HEAD -- .

Revert to previous commit, discarding all changes made locally

  • Command
git reset --hard HEAD

Stage only files that match a given regex

  • Command
find . -name '<regex here>' | xargs git add
  • Example (stage all files with extension .fr.resx)
find . -name '*.fr.resx' | xargs git add

Add a submodule to existing Git repository

  • Command
git submodule add <gitRepositoryUrl> <path>
  • Example
git submodule add https://github.com/INKolevTest/BootstrapThemes.git Source/Web/Web/Content/BootstrapThemes
git commit -m "Added BootstrapThemes submodule" 
git push

Make a submodule visible in the existing Git repository

  • Command (execute in the root folder where the .git directory is)
git submodule init
git submodule update
  • init makes git go through your .gitmodules file and automatically adds an entry to .git/config for each submodule
  • update clones the specified submodules into our repo (the parent project)

Update submodule and parent repo in one step

  • Command
git push --recurse-submodules=check

Create alias for some operation

  • Command
git config alias.pushall "push --recurse-submodules=on-demand"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment