Skip to content

Instantly share code, notes, and snippets.

@AlexanderFabisch
Last active October 18, 2016 16:04
Show Gist options
  • Save AlexanderFabisch/9208065 to your computer and use it in GitHub Desktop.
Save AlexanderFabisch/9208065 to your computer and use it in GitHub Desktop.
Working with git

Working with git

Complex git operations and commands that I always forget...

Remove Submodule

Source

  1. Delete the relevant section from the .gitmodules file.
  2. git add .gitmodules
  3. Delete the relevant section from .git/config.
  4. git rm --cached <path_to_submodule> (no trailing slash).
  5. rm -rf .git/modules/<path_to_submodule>
  6. git commit -m "Removed submodule <name>"
  7. Delete the now untracked submodule files
  8. rm -rf <path_to_submodule>

Subtree Merging

Source

  1. git remote add <subtree-merge-repo-name> <url>
  2. git fetch <subtree-merge-repo-name>
  3. git checkout -b <some_new_branch> <subtree-merge-repo-name>/<branch>
  4. git checkout master
  5. git read-tree --prefix=<subfolder>/ -u <some_new_branch>
  6. git merge --squash -s subtree --no-commit <some_new_branch>

Delete a Remote Branch

Source

  1. remove local branch from your machine: git branch -d the_local_branch
  2. remove a remote branch: git push origin :the_remote_branch

Change Timestamp of the Last Commit

Source

git commit --amend --date="$(date -R)"

Squash Commits

Source

  • You are on <branch1> and want to squash and merge commits from <branch2>: git merge --squash <branch2>
  • You are on <branch2> and want to rebase on <branch1> and squash commits from on top: git rebase -i <branch1>

Export Project

Source

git archive master | tar -x -C ~/target

Pull after Forced Push

git fetch
git reset <remote>/<branch> --hard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment