
ngrok-gitconfig
Generate a gitconfig snippet that rewrites each target source domain to the active ngrok tunnel URL.
CHINESE README
ไธญๆ่ฏดๆ
Main Features
๐ Single-Purpose Command: Fetch active ngrok tunnel URLs and write them as a gitconfig snippet
๐ Plug-In Design: Output snippet plugs into ~/.gitconfig via git's [include] mechanism
๐ Symlink-Based Switching: Toggle between LAN and ngrok paths via a single ln -sf
๐ Multi-Account Support: Pick from a list of ngrok api keys via the -n index flag
Installation
go install github.com/yylego/ngrok-gitconfig/cmd/ngrok-gitconfig@latest
Usage
# Fetch active ngrok tunnels and write the snippet (default api key index 0)
ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok
# Pick api key index 1
ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok -n 1
Flags
| Flag |
Default |
Note |
--config / -c |
(required) |
path to YAML config |
--output / -o |
(required) |
output path of the gitconfig snippet |
--choose / -n |
0 |
api key index |
Configuration
YAML config โ ~/configs/ngrok-gitconfig.yaml
api_keys:
- "<ngrok api key 1>" # account 1
- "<ngrok api key 2>" # account 2 (extras OK, pick via -n flag)
targets:
- "https://gitlab.example.com/"
- "http://gitlab.example.com/"
targets are paired by index with the tunnel URLs returned by the ngrok API.
Wire up ~/.gitconfig with [include]
Add at the top of ~/.gitconfig:
[include]
path = ~/.gitconfig.gitlab.active
LAN snippet โ ~/.gitconfig.gitlab.local
Hand-written, does not change:
[url "http://192.168.1.100:8080/"]
insteadof = https://gitlab.example.com/
[url "http://192.168.1.100:8080/"]
insteadof = http://gitlab.example.com/
ngrok snippet โ ~/.gitconfig.gitlab.ngrok
Touch the snippet file (this command overwrites it on each run):
touch ~/.gitconfig.gitlab.ngrok
Setup symlink
Point active at one of the snippets to start (LAN here):
ln -sf ~/.gitconfig.gitlab.local ~/.gitconfig.gitlab.active
Recommended Aliases
In ~/.zshrc (or ~/.bashrc):
gitlab-use-ngrok() {
ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok "$@" \
&& ln -sf ~/.gitconfig.gitlab.ngrok ~/.gitconfig.gitlab.active
}
alias gitlab-use-local='ln -sf ~/.gitconfig.gitlab.local ~/.gitconfig.gitlab.active'
alias gitlab-use-which='ls -la ~/.gitconfig.gitlab.active'
Usage Examples
# In office (LAN direct)
gitlab-use-local
# Off-LAN (refresh ngrok URLs from API, switch active to ngrok)
gitlab-use-ngrok
# Same as above, pick api key index 1
gitlab-use-ngrok -n 1
# Check which path is now active
gitlab-use-which
๐ License
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- ๐ Mistake reports? Open an issue on GitHub with reproduction steps
- ๐ก Fresh ideas? Create an issue to discuss
- ๐ Documentation confusing? Report it so we can improve
- ๐ Need new features? Share the use cases to help us understand requirements
- โก Performance issue? Help us optimize through reporting slow operations
- ๐ง Configuration problem? Ask questions about complex setups
- ๐ข Follow project progress? Watch the repo to get new releases and features
- ๐ Success stories? Share how this package improved the workflow
- ๐ฌ Feedback? We welcome suggestions and comments
๐ง Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git).
- Navigate: Navigate to the cloned project (
cd repo-name)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation to support client-facing changes
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
๐ Support
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- โญ Give GitHub stars if this project helps you
- ๐ค Share with teammates and (golang) programming friends
- ๐ Write tech blogs about development tools and workflows - we provide content writing support
- ๐ Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! ๐๐๐
GitHub Stars
