Some personal git
commands that have been adapted from aliases. My current
git
config has several aliases that feed into one that I use regularly for
syncing a local repository with it's remote, this looks like:
x-repo = !"f() { git config --get remote.origin.url | sed 's/^.*\\:\\(.*\\)\\.git/\\1/'; }; f"
x-fetch-all = fetch --no-tags --all -p
x-fetch-branch = !"f() { git fetch origin $1:$1; }; f"
x-merge-ff = merge --ff-only
x-branch-current = rev-parse --abbrev-ref HEAD
x-branch-default = !"f() { git remote show origin | grep HEAD | awk '{print $3}'; }; f"
x-branch-tidy = "!f() { git branch -vv | grep ': gone]' | awk '{print $1}' | xargs -n 1 git branch -D; }; f"
up = \
!"f() { \
current=$(git x-branch-current); \
default=$(git x-branch-default); \
git x-fetch-all && \
(git x-merge-ff || true) && \
git x-branch-tidy && \
if [ \"$current\" != \"$default\" ]; then git x-fetch-branch $default; fi; \
}; f"
The end goal of this project is to have a single git-sync
that can be used to
do the same, but hopefully faster.
Prints the current branch for a local repository.
Prints the default branch, eg. main
or master
, for a repository.
Prints the repository, eg. geoffjay/git-utils
.
Prints the full repository url, eg. git@github.com:geoffjay/git-utils
.
Currently there are only builds in the release for x86_64, aarch64 is planned.
This assumes that ~/.local/bin
exists, is in your PATH
, and is where you
want them to go. Adjust the command for your environment if this is not what's
desired.
curl -LO https://github.com/geoffjay/git-utils/releases/latest/download/git-utils-v0.1.1-darwin-x86_64.tar.gz
tar -xf git-utils-v0.1.1-darwin-x86_64.tar.gz -C ~/.local/bin
rm git-utils-v0.1.1-darwin-x86_64.tar.gz
Currently there are only builds in the release for x86_64, arm64 is planned.
This assumes that ~/.local/bin
exists, is in your PATH
, and is where you
want them to go. Adjust the command for your environment if this is not what's
desired.
curl -LO https://github.com/geoffjay/git-utils/releases/latest/download/git-utils-v0.1.1-linux-x86_64.tar.gz
tar -xf git-utils-v0.1.1-darwin-x86_64.tar.gz -C ~/.local/bin
rm git-utils-v0.1.1-linux-x86_64.tar.gz
There is a build for Windows, but I don't have a way to test that so this section will be left as-is for the foreseeable future.
Licensed under the MIT license, see here.