git is essential to our everyday operations when using version control.
- Alias
- Extensions
- Managing Secrets for Git
matrix.dot.files includes many useful aliases to enhance your GIT experience.
git aliases- List your aliasesgit [br,ci,co,df,st]- Common git shortcut string aliasesgit info- Show the remote configuration
git diff-staged- Show the diff of staged files by using the cached flaggit wdiff- Show the diff with Colorgit forget- Removes the copy of the file from the index / staging-area, without touching the working tree copygit ignored- List files ignored by the repo
git revertfile- Recheckout a filegit uncommit- Reset and backout the lastcommit before a push
git purge- remove untracked directories (permanently deletes files)git squash-all- Squash the entire repogit remove-tags- Remove all the tags
(git stash)- Builtin - Record the current state of the working directory and the index, but want to go back to a clean working directory.git unstash- Pop from the Stash back on the checked out files
(git stage) - Builtin - (This is a synonym for git-add)git staged- List what is stagedgit unstage- Unstage a file that was staged
git skipped- List files that are ignored but in the repogit skip- Ignore a local file changes in the repo (like a local config file that is actually in the repo)git unskip- Stop ignoring local file changes in the repo
git markdown-toc- Create a markdown TOC
git last- Show the last line of the log filegit oneline- Show the logs but only one line per entry with entitie informationgit out- Log Oneline origin/main..HEADgit tree- Log with Tree outputgit smartlog- hg smartlog clone - Reference: https://gist.github.com/jessesquires/d0f3fc99be8208394a450ce86443ce7d
git leaks- Scan for secrets recursively in the local directory, not the repo itself using gitleaks.
Git plugins in the shell $PATH slip into the main binary completion similiar to kubectl.
git swap - quickly change current git/github user in the repo
Example: Swap to user shadowbq in current checked out repo
$ git swap shadowbq
shadowbq <shadowbq@gmail.com>Example Options:
usage: ./git swap <username in ~/.gitusers>
usage: ./git swap <username> <email>
Switch Local and Save to Config
usage: ./git swap [--new-user1 || -1] <username> <email>
usage: ./git swap [--new-user2 || -2] <username> <email>
usage: ./git swap [--new-user3 || -3] <username> <email>
Switch Global
usage: ./git swap [--global || -g] <username> <email>The configuration supports three different users [user1,user2,user3]
~/.gitusers
user1name="shadowbq"
user1email="shadowbq@gmail.com"git whoami - Show who you are based on global or local settings in a repo
$> git whoami
shadowbq <shadowbq@gmail.com>git downcase - Downcase all filenames in the current repo!
Note: The global MDF in ~/.gitconfig config is set to 'ignorecase'
Need I say more.. force downcase of filenames in repo. It will git mv the files to the new locations.
It will also set the current repo configuration:
git config core.ignorecase false
git-private "${git_tag}" myorg private-repo "${filename}" "${archive:?}/${filename}" - Download a Published Private Tag from Github using Curl HTTPs REST API.
The wack-o-mole of fetching HTTPS git private repos.
Example usage:
export GITHUB_TOKEN=ABCDEFGHIJ0123456789
git private v0.0.1 myorg private-repo foo.tar.gz /var/tmp/foo.tar.gzExample usage: less secure
GITHUB_TOKEN=ABCDEFGHIJ0123456789 git private v0.0.1 myorg private-repo foo.tar.gz /var/tmp/foo.tar.gzgit proxyclear - Nuke proxy settings
Clearing any proxy settings that may be attached to the current checked out repo.
git md-toc-creator - Markdown Table of Contents Creations script.
You should use MDF Secrets if you don't / can't use SSH as the git protocol. In 2021 they will obsolete the use of passwords in github for HTTPS access to git repositories.
README - Secrets - MDF Secrets with GPG and Bash
On a macOS:
Open KeyChain Access (Via spotlight search) → search GitHub → click GitHub → change and save with your new PAT link
Warning: Tokens have read/write access and should be treated like passwords. If you enter your token into the clone URL when cloning or adding a remote, Git writes it to your .git/config file in plain text, which is a security risk.
$> git push
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/shadowbq/matrix.dot.files.git/'Remove old PW based origin, and convert to PAT. (Note: The space for not logging the history of the TOKEN)
git remote remove origin
git remote add origin https://[USERNAME]:[NEW TOKEN]@github.com/[USERNAME]/[REPO].git
git pushCreate an admin:all Personal access token in Github.
admin:all — admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, repo, user, workflow, write:discussion, write:packagesSave it as MDF Secret and load it via the GPG key method into your shell. Tokens are not passwords that you can set, so using secure mechanism to input the token is very important.
Investigate the current credential setting:
$> git config --show-origin --get credential.helper
file:/Users/smacgregor/.gitconfig osxkeychain
$> git config --global credential.helper`Unset if not wanted/needed.
git config --global --unset credential.helper
Git Credential Manager Core (GCM Core) is another way to store your credentials securely and connect to GitHub over HTTPS. With GCM Core, you don't have to manually create and store a PAT, as GCM Core manages authentication on your behalf, including 2FA (two-factor authentication).
- Install Git using Homebrew:
$ brew install git- Install GCM Core using Homebrew:
$ brew tap microsoft/git
$ brew install --cask git-credential-manager-coreFor MacOS, you don't need to run git config because GCM Core automatically configures Git for you.
For Linux, install Git and GCM Core, then configure Git to use GCM Core.
-
Install Git from your distro's packaging system. Instructions will vary depending on the flavor of Linux you run.
-
Install GCM Core. See the instructions in the GCM Core repo, as they'll vary depending on the flavor of Linux you run.
-
Configure Git to use GCM Core. There are several backing stores that you may choose from, so see the GCM Core docs to complete your setup. For more information, see "GCM Core Linux."
