A collection of small scripts to make the git workflow easier
These scripts are intended for making GitHub and GitLab workflows easier. They support a single "central" repo as well as the common dual "upstream/fork" repo setups. For forked repos, both of the following setups are supported:
- "standard", recommended by GitHub's help on configuring remotes
and used by both GitHub's gh tool and GitLab's glab tool
(upstream named
upstreamand fork namedorigin) - "alternate", used by GitHub's hub tool
(upstream named
originand fork named<user>)
To install, clone the directory and run the install script:
git clone https://github.com/nicksay/git-scripts.git
cd git-scripts
./install.shThis will place the scripts in $HOME/bin.
Since the scripts are intended for making the GitHub workflow easier, the best usage documentation is the lifecycle of a change.
To get started, create a new branch:
git new "my-change"Then, edit and commit code as normal.
When you're ready, create a pull request for your change:
git hub-pull-requestThis will prepare your branch for a pull request by rebasing on the latest commits from upstream, push your branch to your fork, and create a pull request using the gh tool or hub tool if one's installed or open the GitHub compare URL if not.
After your pull request is accepted, you can finish up:
git doneThis will make sure both your local and fork repos are updated with the latest changes from upstream and remove branches have been merged or squashed with main, including the one you created for your change.
Prints the upstream and fork remotes, finding GitHub $GIHUB_USER remotes
if possible.
git remotes [--upstream|--fork]Create a GitHub pull request.
Calls git prepare and git push followed by one of the following:
gh pr create, hub pull-request, or opening a compare URL.
Prints the GitHub user.
git hub-userFinds the value from the following sources in descending order:
- environment (
$GITHUB_USER) - .git/config or ~/.gitconfig (
git config --get hub.user) - ~/.config/gh/hosts.yml (
github.com -> user) - ~/.config/hub (
github.com -> [0] -> user)
If a value is not found, prompts for one and saves it to .git/config.
Prints the GitLab user.
git lab-userFinds the value from the following sources in descending order:
- environment ($GITLAB_USER)
- git config --get lab.user
- glab config get user
If a value is not found, prompts for one and saves it to .git/config.
git doneFinishes a branch: returns to main, runs git sync and git tidy.
git new <branch>Creates a new branch from main.
Arguments:
branch: the name of the new branch to create
git prepare [upstream] [branch]Prepare your current branch for a pull request.
Arguments:
upstream: defaults togit remotes --upstreambranch: defaults to "main"
Fetches the latest commits from [upstream] and rebases on
[upstream]/[branch]. Automatically avoids interactive mode unless
needed and will rebase --autosquash all commits made with
commit --fixup and commit --squash without needing to launch an
editor.
Afterward, run git push to update an existing pull request on GitHub.
git sync [upstream] [fork] [branch]Keep your local and fork repos synced with upstream.
Arguments:
upstream: defaults togit remotes --upstreamfork: defaults togit remotes --forkbranch: defaults to the current branch
Pulls the latest commits from [upstream]/[branch] and then pushes
to [fork]/[branch]. Uses pull --prune and push --prune to remove
old branch references.
git tidy [branch]Deletes branches merged or squashed with a base branch.
Arguments:
branch: defaults to "main"