Git Extras Cheatsheet | release, scp, fork, alias, bulk, clear, repl, squash, ..

ยท 3551 words ยท 17 minute read

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 ๐Ÿ”—

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 .

Share: