Scripts and aliases that make git easier to use
Displays the differences between two branches or commits using difftool. commit2 defaults to HEAD.
Displays the differences for path between the working directory and HEAD all at once using difftool rather than one at a time.
Fetches and fast-forwards (if possible) all branches in the repo.
Fetches and fast-forwards (if possible) all branches in the repo and all its submodules.
For all git repositories in any subdirectories, fetches all branches and tags from all remotes.
Fetches the upstream of the current branch, then fast-forwards the branch and updates the submodules if it is behind and hasn't diverged. Otherwise reports how many commits it is ahead or behind.
Creates a temporary branch named wip/${user}/${timestamp} from uncommitted changes and pushes it to origin so that it can be referenced elsewhere.
Rebases all branches matching pattern onto branch.
For example, I do this a lot: git-rebase-all develop feature
Removes a submodule from the repo completely.
Resets the current branch to commit and retains the removed commits in a new branch named branch.
Note: The new branch name defaults to wip/${branch}-saved-${timestamp} if none is provided.
Shows the differences between commit and its predecessor using difftool.
Unifies two branches such that commits in branch1 are followed by commits in branch2.
Runs uncrustify on all modified or added c/cpp/h files in the working tree. Set the executable and config file with git config uncrustify.path and git config uncrustify.config; see git-uncrustify -h for the fallbacks.
Commits submodule (name or path), or with --all every submodule, whose checked-out HEAD differs from the superproject's recorded commit, with a message showing the new short hash. Each submodule is committed separately, and other staged changes are not included.
For each subdirectory that is a Git repository, fetches all remotes, rebases the current branch onto its upstream, and initializes and updates submodules. If the update succeeded and the upstream repository is archived on GitHub, the directory is moved into archived. Skips worktrees and the 3rdParty and archived directories. A detached HEAD, missing upstream, or failed rebase is reported and the branch is left unchanged. A failed fetch, rebase, or submodule update does not stop the remaining repositories, and the exit status is nonzero if anything failed.
Example Git configuration file with custom settings including:
- Core settings (preload index, file system cache, editor configuration)
- Git LFS filter configuration
- User identity settings
- Diff and merge tool settings (Araxis Merge)
To use this configuration, copy it to your user directory and adjust the paths and user information as needed.
Example NPM configuration file with settings for initializing new npm projects, including:
- Author email
- Author name
- Author URL
- License type
- Project version
Git commands with options that I use a lot.
- alias grevert='git checkout --': Undoes any unstaged changes to the specified files
- alias gsquash='git rebase -i': Rewrites history
- alias gunstage='git reset HEAD': Unstages the specified files
- alias ggraph='git log --graph ...: Draws the branch graph the way that I like it
- alias glog='git log ...: Formats the log the way that I like it
- alias gamend='git commit --amend --no-edit': No-fuss amended commits