Git
Various Git aliases from others
Push existing repository to new remote
git remote add <name of new remote> <HTTPS or SSH URL>git push <name of new remote> masterPretty-print branch graph
git log --all --decorate --oneline --graphMove ‘master’ back
git checkout mastergit reset --hard <old_commit_id>git push -f origin masterReplay changes from ‘master’
git checkout mastergit pullgit checkout different_branchgit rebase -Xtheirs mastergit push --forceShow changed files in commit hash
From here.
git diff-tree --no-commit-id --name-only <commit hash>Create patch file from diff
git diff file.json > file.patchCreate patch file from commit
git show <commit hash> > commit.patchApply patch file
git apply commit.patchBulk create patch files from files
From here.
OLDIFS=$IFS; IFS=';' \ blocks=$(git diff | sed -n '/diff/,/(diff|$)/ {/diff / s/^/\;/; p}'); \ for block in ${blocks#;}; do \ echo "$block" > $(echo "$block" | head -n 1 | rev | cut -d "/" -f 1 | rev).patch; \ done; \IFS=$OLDIFSShow diff of stashed hunk
git stash show -p [stash@{N}]Bulk create separate stashes of files
git status -s | cut -d " " -f 3 | xargs -I {} git stash push {} -m "{}"Pop every entry from the stash
git stash list | cut -d ":" -f 1 | xargs -I {} git stash popMove unpushed commits to new branch
git checkout -b new_branchgit checkout mastergit reset --hard origin/masterCopy commit to current branch
git cherry-pick <commit hash>Undo pushed commit that wasn’t pulled
git reset HEAD^ --hardgit push --force originView history of specific function in file
git log -L :<function>:<file>Speed up Git for larger repositories
git config feature.manyFiles 1Search through history for a word
git rev-list --all | ( while read revision; do git grep -F 'word' "$revision"; done; )Delete remote branch
git push origin --delete branch/nameBulk reset author of multiple commits
git rebase --onto HEAD~9 --exec "git commit --amend --reset-author --no-edit" HEAD~9Re-order commits
git rebase --interactiveSearch for string in a commit message
git log --all -i --grep='something'Search for string in commit contents
git grep 'something' $(git rev-list --all)Clean new untracked files and directories
-d: recurse into directories as well-f: go ahead with deletion-n: dry-run
$ git clean -dnWould remove mdbookWould remove public/snippets/$ git clean -dfRemoving mdbookRemoving public/snippets/Find out number of changes for author
git log --pretty=format:'%an' <file> | sort | uniq -c | sort -u | sort -n