https://github.com/CNG/dotfiles/blob/master/files/zsh/config/git/functions/git-import
# creates patches from $object (either file or dir) including history
cd some_repo
git format-patch --thread -o "$temp_dir" --root -- "$object"
# replay patches into other repo
cd other_repo
git am "$temp_dir"/*.patch || git am --abort
git clone --recursive https://host/dir/repo.git
cd cloned-repo
git submodule update --init --recursive
git remote -v
git remote rename old_name new_name
git config --global user.name "John Doe"
git config --global user.email [email protected]
git config --local user.name "John Doe"
git config --local user.email [email protected]
Rewritting the remote URL is especially useful when using submodules since submodules usually keep their remote regardless how the parent got cloned (setting can also be done per repo).
# rewrite SSH
git config --global url.https://gitserver/.insteadOf ssh://git@gitserver/
# rewrite git protocol
git config --global url.https://gitserver/.insteadOf git@gitserver/
git commit --amend --author "name <[email protected]>"
git rebase -i --root
Rebase commits starting and including COMMIT
on top of branch
:
git rebase --onto branch SHA_OF_COMMIT^
The ^
attached to SHA_OF_COMMIT
is crucial so that COMMIT
is also included in the rebase.