Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

mznu/git-profile

Repository files navigation

git-profile

Git custom subcommand for switching the global ~/.gitconfig between named profile files.

TL;DR

git profile add work                   # Save the current ~/.gitconfig as "work"
git profile add personal --from ~/personal.gitconfig
git profile list                       # See stored profiles
git profile work                       # Replace ~/.gitconfig with "work"
git profile                            # Print the active profile name
git profile show                       # Inspect the active profile
git profile diff                       # Compare active profile with ~/.gitconfig
git profile export work ./work.gitconfig

Install

Supported platforms:

  • macOS, Linux, and WSL 2
  • amd64 and arm64

macOS and Linux

Install with Homebrew:

brew install mznu/tap/git-profile

Or download a release archive for your OS and architecture, then install it manually:

tar -xzf git-profile_1.0.0_linux_amd64.tar.gz git-profile
mkdir -p ~/.local/bin
install -m 0755 git-profile ~/.local/bin/git-profile

Use the matching archive name for macOS (darwin) or ARM (arm64). Make sure ~/.local/bin is on your PATH.

If macOS blocks a manually downloaded binary, remove the quarantine attribute after verifying that the archive came from a trusted release:

xattr -d com.apple.quarantine ~/.local/bin/git-profile

Windows with WSL 2

Native Windows binaries are not published. On Windows, use WSL 2 and install git-profile inside the WSL distribution with the macOS and Linux instructions above. The WSL binary manages the WSL user's ~/.gitconfig.

Build From Source

Build from source with Go:

go build -o git-profile ./cmd/git-profile
export PATH="$PWD:$PATH"

Usage

All commands are run as git profile ....

Command Description
(no arguments) Print the active profile name, or none when no profile is active.
list List stored profiles. The active profile is marked with *.
add NAME Create a profile by copying the current ~/.gitconfig.
add NAME --from PATH Create a profile from another Git config file.
NAME Switch ~/.gitconfig to the named profile.
show [NAME] Print a stored profile without switching. When NAME is omitted, show the active profile.
diff [NAME] Show file differences between a stored profile and the current ~/.gitconfig. When NAME is omitted, diff the active profile.
remove NAME Remove a stored profile. The active profile cannot be removed.
rename OLD [NEW] Rename a stored profile. When NEW is omitted, prompt for it.
export NAME [DESTINATION] Copy a stored profile to a file. Use --force to overwrite an existing destination.

Run git profile -h, git profile help [command], or git profile [command] -h for command-specific help. Profile names can contain letters, numbers, ., _, and -, and cannot use reserved command names.

Shell Completion

Built-in shell auto-completion is not currently published. git-profile is installed as a Git custom subcommand and used as git profile; generic Cobra completion scripts target profile as a standalone command instead of the Git subcommand form, so the default completion command is intentionally disabled.

How It Works

  • git profile add NAME copies the current ~/.gitconfig into a named profile file. Use --from to copy another Git config file instead.
  • Profile files are stored as ~/.config/git-profile/profiles/NAME.gitconfig.
  • Running git profile NAME validates the stored profile with git config, then replaces ~/.gitconfig with that profile using an atomic file write.
  • The active profile name and switch time are recorded in ${XDG_CONFIG_HOME:-~/.config}/git-profile/state.json.
  • git profile list, show, diff, rename, remove, and export operate on those stored profile files; remove does not delete the active profile.

Releasing

Releases are automated with GoReleaser. Pushing a SemVer tag that starts with v runs tests, builds Linux and macOS artifacts, uploads checksums, and creates a GitHub Release.

git tag v1.0.0
git push origin v1.0.0

Validate the release configuration locally before tagging:

goreleaser release --snapshot --clean

About

Git custom subcommand for switching the global ~/.gitconfig between named profile files

Resources

License

Stars

Watchers

Forks

Contributors

Languages