Autogit - never forget to pull the latest changes again
Even experienced programmers make mistakes - lately I've been forgetting to git pull on my local repos when working quickly, leading my poor colleague Max to have to Slack me messages like this while we're on pair-coding calls:
Sorry, Max! Forgetting to git pull means we're more likely to open a pull request with outdated code. We can do better than this, and use automation to augment our fallible human nature.
Introducing autogit
Autogit is an open-source shell script that handles all your common git concerns, such as:
- stashing uncommitted changes
- determining the default branch and pulling the latest
- fetching all new branches and pruning outdated branches
- handling the case where a GitHub remote has changed its default branch from master to main
It is designed to be run everytime you change directories into a local git repository.
In this way, autogit attempts to stay out of your way, run as quickly as possible, never run when unnecessary, and otherwise remove the cognitive burden around remembering to git pull when you're in the middle of an incident and trying to move quickly.
You can easily wire up autogit to your cd
command, if you'd like to run it that way. If you'd rather configure your environment to run it at a different point, that's fine, too!
Autogit features
1. Automatically handles default branch changes from master to main
Oftentimes, developers find themselves cloning and working with repositories that have non-uniform default branches in GitHub.
Project A may use a default branch of master, while Project B, C, and D use main. What's a poor programmer to do when they're trying to put out a fire?
Just use autogit - it can detect this edge case, checkout the correct default branch locally, and pull the latest changes for you.
2. Designed to handle dirty worktrees and uncommitted changes
Autogit is designed to assist working developers. If you have a feature branch checked out in the git repo that you cd
into, autogit will automatically stash your changes,
checkout your default branch and pull, then checkout your original branch and re-apply your stashed changes.
3. Smart about when to work and when to do nothing
Autogit can tell when you already have the latest changes, and you're just changing into a sub-directory of the same git repository.
There's no real work to do in this case, so autogit returns early to keep your developer workflow snappy. In additon, autogit only runs on git repositories.
You should notice autogit fetching your latest changes whenever you change into a repo, and otherwise you should never notice autogit at all!
4. Auto fetching and pruning
Never miss a new feature branch or operate on a stale branch again. Autogit also fetches automatically when it is updating your local repo.
Thanks, and a request
Thank you for reading! If you've found this post helpful at all, please consider:
- Sharing it with a friend
- Signing up for my newsletter
- Sponsoring me on GitHub
Every little bit helps and I greatly appreciate your taking the time to read my post!