Git Extras Cheatsheet | release, scp, fork, alias, bulk, clear, repl, squash, ..
git extras ๐
Git extension pack.
Install or upgrade git-extras
commands:
git extras update
Display help:
git extras --help
Display version:
git extras --version
git clear-soft ๐
Clear a Git working directory as if it was freshly cloned with the current branch excluding files in .gitignore
.
Reset all tracked files and delete all untracked files:
git clear-soft
git release ๐
Create a Git tag for a release.
Create and push a release:
git release tag_name
Create and push a signed release:
git release tag_name -s
Create and push a release with a message:
git release tag_name -m "message"
git contrib ๐
Display commits from a author.
Display all commit hashes and their corresponding commit messages from a specific author:
git contrib author
git delete-submodule ๐
Delete a submodule from a git
repository.
Delete a specific submodule:
git delete-submodule path/to/submodule
git graft ๐
Merge commits from a branch into another branch and delete the source branch.
Merge all commits not present on the target branch from the source branch to target branch, and delete the source branch:
git graft source_branch target_branch
git merge-repo ๐
Merge two repository histories.
Merge a repository’s branch into the current repository’s directory:
git merge-repo path/to/repo branch_name path/to/directory
Merge a remote repository’s branch into the current repository’s directory, not preserving history:
git merge-repo path/to/remote_repo branch_name .
git abort ๐
Abort an ongoing rebase, merge, or cherry-pick.
Abort a Git rebase, merge, or cherry-pick:
git abort
git gh-pages ๐
Create a new branch inside the current repository called gh-pages
.
Create the GitHub pages branch inside the repository in the current directory:
git gh-pages
git rename-branch ๐
Rename a Git branch.
Rename the branch you are currently on:
git rename-branch new_branch_name
Rename a specific branch:
git rename-branch old_branch_name new_branch_name
git reset-file ๐
Revert a file to HEAD or a commit.
Reset a file to HEAD:
git reset-file path/to/file
Reset a file to a specific commit:
git reset-file path/to/file commit_hash
git guilt ๐
Show total blame count for files with unstaged changes or calculate the change in blame between two revisions.
Show total blame count:
git guilt
Calculate the change in blame between two revisions:
git guilt first_revision last_revision
Show author emails instead of names:
git guilt --email
Ignore whitespace only changes when attributing blame:
git guilt --ignore-whitespace
Find blame delta over the last three weeks:
git guilt 'git log --until="3 weeks ago" --format="%H" -n 1'
Find blame delta over the last three weeks (git 1.8.5+):
git guilt @{3.weeks.ago}
git rename-remote ๐
Change remote for pulling and pushing.
Change the upstream remote to origin:
git rename-remote upstream origin
git sync ๐
Sync local branches with remote branches.
Sync the current local branch with its remote branch:
git sync
Sync the current local branch with the remote main branch:
git sync origin main
Sync without cleaning untracked files:
git sync -s remote_name branch_name
git missing ๐
Show commits which aren’t shared between two branches.
Show commits which aren’t shared between the currently checked-out branch and another branch:
git missing branch
Show commits which aren’t shared between two branches:
git missing branch_1 branch_2
git brv ๐
Print a list of branches, sorted by last commit date.
List each branch showing date, latest commit hash and message:
git brv
git effort ๐
Display how much activity a file has had, showing commits per file and “active days” i.e. total number of days that contributed to the file.
Display each file in the repository, showing commits and active days:
git effort
Display files modified by a specific number of commits or more, showing commits and active days:
git effort --above 5
Display files modified by a specific author, showing commits and active days:
git effort -- --author="username"
Display files modified since a specific time/date, showing commits and active days:
git effort -- --since="last month"
Display only the specified files or directories, showing commits and active days:
git effort path/to/file_or_directory1 path/to/file_or_directory2 ...
Display all files in a specific directory, showing commits and active days:
git effort path/to/directory/*
git magic ๐
Automate add, commit, and push routines.
Commit changes with a generated message:
git magic
[a]dd untracked files and commit changes with a generated message:
git magic -a
Commit changes with a custom [m]essage:
git magic -m "custom_commit_message"
[e]dit the commit [m]essage before committing:
git magic -em "custom_commit_message"
Commit changes and [p]ush to remote:
git magic -p
Commit changes with a [f]orce [p]ush to remote:
git magic -fp
git scp ๐
Copy files from the current working tree to the working directory of a remote repository.
Uses rsync
to transfer files.
Copy unstaged files to a specific remote:
git scp remote_name
Copy staged and unstaged files to a remote:
git scp remote_name HEAD
Copy files that has been changed in the last commit and any staged or unstaged files to a remote:
git scp remote_name HEAD~1
Copy specific files to a remote:
git scp remote_name path/to/file1 path/to/file2 ...
Copy a specific directory to a remote:
git scp remote_name path/to/directory
git delete-tag ๐
Delete existing local and remote tags.
Delete a tag:
git delete-tag tag_version
git merge-into ๐
Merge one branch into another branch.
Merge a source branch into a specific destination branch:
git merge-into source_branch destination_branch
Merge current branch into a specific destination branch:
git merge-into destination_branch
git ignore ๐
Show/update .gitignore
files.
See also git ignore-io .
Show the content of all global and local .gitignore
files:
git ignore
Ignore file(s) privately, updating .git/info/exclude
file:
git ignore file_pattern --private
Ignore file(s) locally, updating local .gitignore
file:
git ignore file_pattern
Ignore file(s) globally, updating global .gitignore
file:
git ignore file_pattern --global
git ignore-io ๐
Generate .gitignore files from predefined templates.
List available templates:
git ignore-io list
Generate a .gitignore template:
git ignore-io item_a,item_b,item_n
git psykorebase ๐
Rebase a branch on top of another using a merge commit and only one conflict handling.
Rebase the current branch on top of another using a merge commit and only one conflict handling:
git psykorebase upstream_branch
Continue after conflicts have been handled:
git psykorebase --continue
Specify the branch to rebase:
git psykorebase upstream_branch target_branch
git cp ๐
Copy an existing file to a new location, preserving history.
Copy an existing file in a Git repo, staying in the same directory:
git cp file new_file
Copy an existing file in a Git repo and place it elsewhere:
git cp path/to/file path/to/new_file
git delete-squashed-branches ๐
Delete branches that have been “squashed-merged” into a specified branch and checkout. If no branch is specified, default to the currently checked out branch.
Delete all branches that were “squash-merged” into the current checked out branch:
git delete-squashed-branches
Delete all branches that were “squash-merged” into a specific branch:
git delete-squashed-branches branch_name
git obliterate ๐
Delete files and erase their history from a Git repository.
Erase the existence of specific files:
git obliterate file_1 file_2 ...
Erase the existence of specific files between 2 commits:
git obliterate file_1 file_2 ... -- commit_hash_1..commit_hash_2
git fork ๐
Fork a GitHub repo. Like git clone
but forks first.
Fork and clone a GitHub repository by its URL:
git fork https://github.com/abanoubha/ocr
Fork and clone a GitHub repository by its slug:
git fork abanoubha/ocr
git fresh-branch ๐
Create an empty local branch.
Create an empty local branch:
git fresh-branch branch_name
git alias ๐
Create shortcuts for Git commands.
List all aliases:
git alias
Create a new alias:
git alias "name" "command"
Search for an existing alias:
git alias ^name
git reauthor ๐
Change details about an author identity. Since this command rewrites the Git history, --force
will be needed when pushing next time.
Change an author’s email and name across the whole Git repository:
git reauthor --old-email <[email protected]> --correct-email <[email protected]> --correct-name "name"
Change the email and name to the ones defined in the Git config:
git reauthor --old-email <[email protected]> --use-config
Change the email and name of all commits, regardless of their original author:
git reauthor --all --correct-email <[email protected]> --correct-name name
git mr ๐
Check out GitLab merge requests locally.
Check out a specific merge request:
git mr mr_number
Check out a merge request from a specific remote:
git mr mr_number remote
Checkout a merge request from its URL:
git mr url
Clean up old merge request branches:
git mr clean
git utimes ๐
Change files modification time to their last commit date. Does not touch files that are in the working tree or index.
Change all files modification time to their last commit date:
git utimes
Change files modification time that are newer than their last commit date, preserving original modification time of files that were committed from the local repository:
git utimes --newer
git create-branch ๐
Create a Git branch in a repository.
Create a local branch:
git create-branch branch_name
Create a branch locally and on origin:
git create-branch --remote branch_name
Create a branch locally and on upstream (through forks):
git create-branch --remote upstream branch_name
git bulk ๐
Execute operations on multiple Git repositories.
Register the current directory as a workspace:
git bulk --addcurrent workspace_name
Register a workspace for bulk operations:
git bulk --addworkspace workspace_name /absolute/path/to/repository
Clone a repository inside a specific directory then register the repository as a workspace:
git bulk --addworkspace workspace_name /absolute/path/to/parent_directory --from remote_repository_location
Clone repositories from a newline-separated list of remote locations then register them as workspaces:
git bulk --addworkspace workspace-name /path/to/root/directory --from /path/to/file
List all registered workspaces:
git bulk --listall
Run a Git command on the repositories of the current workspace:
git bulk command command_arguments
Remove a specific workspace:
git bulk --removeworkspace workspace_name
Remove all workspaces:
git bulk --purge
git pull-request ๐
git pull-request: Create a pull request for a project on GitHub.
Create a pull request for a project on GitHub:
git pull-request target_branch
git clear ๐
Clear a Git working directory as if it was freshly cloned with the current branch including files in .gitignore
.
Reset all tracked files and delete all untracked files even if they are included in the .gitignore
:
git clear
git repl ๐
Git REPL (read-evaluate-print-loop) - an interactive Git shell.
Start an interactive Git shell:
git repl
Run a Git command while in the interactive Git shell:
git_subcommand command_arguments
Run an external (non-Git) command while in the interactive Git shell:
!command command_arguments
Exit the interactive Git shell (or press Ctrl + D):
exit
git undo ๐
Undo recent commits.
Remove the most recent commit:
git undo
Remove a specific number of the most recent commits:
git undo 3
git delete-branch ๐
Delete local and remote Git branches.
If deleting the checked out branch, only the remote branch will be deleted.
Delete one or more local and remote Git branches:
git delete-branch branch_name1 branch_name2 ...
git rebase-patch ๐
git rebase-patch: Find the commit the patch applies to and do a rebase.
Find the commit the patch applies to and do a rebase:
git rebase-patch patch_file
git paste ๐
Send commits to a pastebin site using pastebinit
.
Send the patches between the current branch and its upstream to a pastebin using pastebinit
:
git paste
Pass options to git format-patch
in order to select a different set of commits (@^
selects the parent of HEAD, and so the currently checked out commit is sent):
git paste @^
git authors ๐
Generate a list of committers of a Git repository.
Print a full list of committers to stdout
instead of to the AUTHORS
file:
git authors --list
Append the list of committers to the AUTHORS
file and open it in the default editor:
git authors
Append the list of committers, excluding emails, to the AUTHORS
file and open it in the default editor:
git authors --no-email
git lock ๐
Lock a file in a Git repository from being modified by a commit.
Disable the ability to commit changes of a local file:
git lock path/to/file
git unlock ๐
Unlock a file in a Git repository so it can be modified by a commit.
Enable the ability to commit changes of a previously-locked local file:
git unlock path/to/file
git commits-since ๐
Display commits since a time or date.
Display commits since yesterday:
git commits-since yesterday
Display commits since last week:
git commits-since last week
Display commits since last month:
git commits-since last month
Display commits since yesterday 2pm:
git commits-since yesterday 2pm
git delete-merged-branches ๐
Delete branches that are listed in git branch --merged
excluding master.
Delete merged branches:
git delete-merged-branches
git rscp ๐
Reverse git scp
- copy files from the working directory of a remote repository to the current working tree.
Copy specific files from a remote:
git rscp remote_name path/to/file1 path/to/file2 ...
Copy a specific directory from a remote:
git rscp remote_name path/to/directory
git force-clone ๐
Provides the basic functionality of git clone
, but if the destination Git repository already exists it will force-reset it to resemble a clone of the remote.
Clone a Git repository into a new directory:
git force-clone remote_repository_location path/to/directory
Clone a Git repository into a new directory, checking out an specific branch:
git force-clone -b branch_name remote_repository_location path/to/directory
Clone a Git repository into an existing directory of a Git repository, performing a force-reset to resemble it to the remote and checking out an specific branch:
git force-clone -b branch_name remote_repository_location path/to/directory
git squash ๐
Squash multiple commits into a single commit.
Merge all commits from a specific branch into the current branch as a single commit:
git squash source_branch
Squash all commits starting with a specific commit on the current branch:
git squash commit
Squash the n
latest commits and commit with a message:
git squash HEAD~n "message"
Squash the n
latest commits and commit concatenating all individual messages:
git squash --squash-msg HEAD~n
git changelog ๐
Generate a changelog report from repository commits and tags.
Update existing file or create a new History.md
file with the commit messages since the latest Git tag:
git changelog
List commits from the current version:
git changelog --list
List a range of commits from the tag named 2.1.0
to now:
git changelog --list --start-tag 2.1.0
List pretty formatted range of commits between the tag 0.5.0
and the tag 1.0.0
:
git changelog --start-tag 0.5.0 --final-tag 1.0.0
List pretty formatted range of commits between the commit 0b97430
and the tag 1.0.0
:
git changelog --start-commit 0b97430 --final-tag 1.0.0
Specify CHANGELOG.md
as the output file:
git changelog CHANGELOG.md
Replace contents of current changelog file entirely:
git changelog --prune-old
git summary ๐
Display information about a Git repository.
Display data about a Git repository:
git summary
Display data about a Git repository since a commit-ish:
git summary commit|branch_name|tag_name
Display data about a Git repository, merging committers using different emails into 1 statistic for each author:
git summary --dedup-by-email
Display data about a Git repository, showing the number of lines modified by each contributor:
git summary --line
git count ๐
git count: Print the total number of commits.
Print the total number of commits:
git count
Print the number of commits per contributor and the total number of commits:
git count --all
git pr ๐
Check out GitHub pull requests locally.
Check out a specific pull request:
git pr pr_number
Check out a pull request from a specific remote:
git pr pr_number remote
Check out a pull request from its URL:
git pr url
Clean up old pull request branches:
git pr clean
git locked ๐
List locked files in a Git repository.
List all local locked files:
git locked
git browse ๐
View an upstream repository in the default browser.
Open the first upstream in the default browser:
git browse
Open a specific upstream in the default browser:
git browse upstream
git show-tree ๐
Show a decorated tree graph with all branches of a Git repository, showing annotations.
Show a decorated tree graph for all branches annotated with tags and branch names:
git show-tree
git coauthor ๐
Add another author to the latest commit. Since this command rewrites the Git history, --force
will be needed when pushing next time.
Insert an additional author to the last Git commit:
git coauthor name <[email protected]>
git setup ๐
Create a Git repository in a directory and commit all files.
Create a Git repository in the current directory and commit all files:
git setup
Create a Git repository in a specific directory and commit all files:
git setup path/to/directory
git standup ๐
See commits from a specified user.
Show a given author’s commits from the last 10 days:
git standup -a name|email -d 10
Show a given author’s commits from the last 10 days and whether they are GPG signed:
git standup -a {[name|email}} -d 10 -g
Show all the commits from all contributors for the last 10 days:
git standup -a all -d 10
Display help:
git standup -h
git sed ๐
Replace patterns in git-controlled files using sed .
Replace the specified text in the current repository:
git sed 'find_text' 'replace_text'
Replace the specified text and then commit the resulting changes with a standard commit message:
git sed -c 'find_text' 'replace_text'
Replace the specified text, using regular expressions:
git sed -f g 'find_text' 'replace_text'
Replace a specific text in all files under a given directory:
git sed 'find_text' 'replace_text' -- path/to/directory
git rename-tag ๐
Rename a Git tag.
Rename an existing Git tag locally and remotely:
git rename-tag old_tag_name new_tag_name
git info ๐
Display Git repository information.
Display remote locations, remote and local branches, most recent commit data and .git/config
settings:
git info
Display remote locations, remote and local branches and most recent commit data:
git info --no-config
git stamp ๐
Stamp the last commit message, with the possibility to reference the issues numbers from your bug tracker or link to its review page.
Stamp the last commit message referencing it with the issue number from your bug tracker:
git stamp issue_number
Stamp the last commit message linking it to its review page:
git stamp Review <https://example.org/path/to/review>
Stamp the last commit message replacing previous issues with a new one:
git stamp --replace issue_number
git browse-ci ๐
Open the current git
repository’s CI website in the default web browser.
Open the current repository’s CI configuration on its upstream website:
git browse-ci
Open the current repository’s CI configuration on its upstream website for a specific remote:
git browse-ci remote
git archive-file ๐
Export all the files of the current Git branch into a Zip archive.
Pack the currently checked out commit into a Zip archive:
git archive-file
git delta ๐
List files that differ from another branch.
List files from the current checked out branch that differ from the main
branch:
git delta main
List files from a specific branch that differ from another specific branch:
git delta branch_1 branch_2
git touch ๐
git touch: Create new files and add them to the index.
Create new files and add them to the index:
git touch path/to/file1 path/to/file2 ...
git root ๐
Print the root directory of the current Git repository.
Print the absolute path of the current Git repository:
git root
Print the current working directory relative to the root of the current Git repository:
git root --relative
git local-commits ๐
Show local commits that haven’t been pushed to origin. Any additional arguments will be passed directly to git log
.
Show commits that haven’t been pushed:
git local-commits
git show-unmerged-branches ๐
Print all branches which are not merged into the current HEAD:
git show-unmerged-branches
Documentation & references ๐
- git extras: https://github.com/tj/git-extras .
- git clear soft: https://github.com/tj/git-extras/blob/master/Commands.md#git-clear-soft .
- git release: https://github.com/tj/git-extras/blob/master/Commands.md#git-release .
- git contrib: https://github.com/tj/git-extras/blob/master/Commands.md#git-contrib .
- git delete submodule: https://github.com/tj/git-extras/blob/master/Commands.md#git-delete-submodule .
- git graft: https://github.com/tj/git-extras/blob/master/Commands.md#git-graft .
- git merge repo: https://github.com/tj/git-extras/blob/master/Commands.md#git-merge-repo .
- git abort: https://github.com/tj/git-extras/blob/master/Commands.md#git-abort .
- git gh pages: https://github.com/tj/git-extras/blob/master/Commands.md#git-gh-pages .
- git rename branch: https://github.com/tj/git-extras/blob/master/Commands.md#git-rename-branch .
- git reset file: https://github.com/tj/git-extras/blob/master/Commands.md#git-reset-file .
- git guilt: https://github.com/tj/git-extras/blob/master/Commands.md#git-guilt .
- git rename remote: https://github.com/tj/git-extras/blob/master/Commands.md#git-rename-remote .
- git sync: https://github.com/tj/git-extras/blob/master/Commands.md#git-sync .
- git missing: https://github.com/tj/git-extras/blob/master/Commands.md#git-missing .
- git brv: https://github.com/tj/git-extras/blob/master/Commands.md#git-brv .
- git effort: https://github.com/tj/git-extras/blob/master/Commands.md#git-effort .
- git magic: https://github.com/tj/git-extras/blob/master/Commands.md#git-magic .
- git scp: https://github.com/tj/git-extras/blob/master/Commands.md#git-scp .
- git delete tag: https://github.com/tj/git-extras/blob/master/Commands.md#git-delete-tag .
- git merge into: https://github.com/tj/git-extras/blob/master/Commands.md#git-merge-into .
- git ignore: https://github.com/tj/git-extras/blob/master/Commands.md#git-ignore .
- git psykorebase: https://github.com/tj/git-extras/blob/master/Commands.md#git-psykorebase .
- git cp: https://github.com/tj/git-extras/blob/master/Commands.md#git-cp .
- git delete squashed branches: https://github.com/tj/git-extras/blob/master/Commands.md#git-delete-squashed-branches .
- git obliterate: https://github.com/tj/git-extras/blob/master/Commands.md#git-obliterate .
- git fork: https://github.com/tj/git-extras/blob/master/Commands.md#git-fork .
- git fresh branch: https://github.com/tj/git-extras/blob/master/Commands.md##git-fresh-branch .
- git alias: https://github.com/tj/git-extras/blob/master/Commands.md#git-alias .
- git reauthor: https://github.com/tj/git-extras/blob/master/Commands.md#git-reauthor .
- git mr: https://github.com/tj/git-extras/blob/master/Commands.md#git-mr .
- git utimes: https://github.com/tj/git-extras/blob/master/Commands.md#git-utimes .
- git create branch: https://github.com/tj/git-extras/blob/master/Commands.md#git-create-branch .
- git bulk: https://github.com/tj/git-extras/blob/master/Commands.md#git-bulk .
- git pull request: https://github.com/tj/git-extras/blob/master/Commands.md#git-pull-request .
- git clear: https://github.com/tj/git-extras/blob/master/Commands.md#git-clear .
- git repl: https://github.com/tj/git-extras/blob/master/Commands.md#git-repl .
- git undo: https://github.com/tj/git-extras/blob/master/Commands.md#git-undo .
- git delete branch: https://github.com/tj/git-extras/blob/master/Commands.md#git-delete-branch .
- git rebase patch: https://github.com/tj/git-extras/blob/master/Commands.md#git-rebase-patch .
- git paste: https://github.com/tj/git-extras/blob/master/Commands.md#git-paste .
- git authors: https://github.com/tj/git-extras/blob/master/Commands.md#git-authors .
- git lock: https://github.com/tj/git-extras/blob/master/Commands.md#git-lock .
- git commits since: https://github.com/tj/git-extras/blob/master/Commands.md#git-commits-since .
- git delete merged branches: https://github.com/tj/git-extras/blob/master/Commands.md#git-delete-merged-branches .
- git scp: https://github.com/tj/git-extras/blob/master/Commands.md#git-scp .
- git force clone: https://github.com/tj/git-extras/blob/master/Commands.md#git-force-clone .
- git squash: https://github.com/tj/git-extras/blob/master/Commands.md#git-squash .
- git changelog: https://github.com/tj/git-extras/blob/master/Commands.md#git-changelog .
- git summary: https://github.com/tj/git-extras/blob/master/Commands.md#git-summary .
- git count: https://github.com/tj/git-extras/blob/master/Commands.md#git-count .
- git pr: https://github.com/tj/git-extras/blob/master/Commands.md#git-pr .
- git locked: https://github.com/tj/git-extras/blob/master/Commands.md#git-locked .
- git browse: https://github.com/tj/git-extras/blob/master/Commands.md#git-browse .
- git show tree: https://github.com/tj/git-extras/blob/master/Commands.md#git-show-tree .
- git coauthor: https://github.com/tj/git-extras/blob/master/Commands.md#git-coauthor .
- git unlock: https://github.com/tj/git-extras/blob/master/Commands.md#git-unlock .
- git setup: https://github.com/tj/git-extras/blob/master/Commands.md#git-setup .
- git standup: https://github.com/tj/git-extras/blob/master/Commands.md#git-standup .
- git sed: https://github.com/tj/git-extras/blob/master/Commands.md#git-sed .
- git rename tag: https://github.com/tj/git-extras/blob/master/Commands.md#git-rename-tag .
- git info: https://github.com/tj/git-extras/blob/master/Commands.md#git-info .
- git stamp: https://github.com/tj/git-extras/blob/master/Commands.md#git-stamp .
- git browse ci: https://github.com/tj/git-extras/blob/master/Commands.md#git-browse-ci .
- git archive file: https://github.com/tj/git-extras/blob/master/Commands.md#git-archive-file .
- git delta: https://github.com/tj/git-extras/blob/master/Commands.md#git-delta .
- git touch: https://github.com/tj/git-extras/blob/master/Commands.md#git-touch .
- git root: https://github.com/tj/git-extras/blob/master/Commands.md#git-root .
- git local commits: https://github.com/tj/git-extras/blob/master/Commands.md#git-local-commits .
- git show unmerged branches: https://github.com/tj/git-extras/blob/master/Commands.md#git-show-unmerged-branches .
- git rebase patch: https://github.com/tj/git-extras/blob/master/Commands.md#git-rebase-patch .
- git ignore io: https://github.com/tj/git-extras/blob/master/Commands.md#git-ignore-io .
I hope this post helps you. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .