Git Town – A high-level command line interface for Git
git-town.com
git-town.com
git is an especially poor choice for wrappers. You're hiding the concepts of staged and unstaged information, branches, tags, remotes, submodules. Regardless of VCS, you're setting yourself up for failure when you buy into a third-party tool's workflow rather than knowing what the hell you're doing.
Pick up git as you go along. Rather than a tool doing who knows what behind the scene. If you really goof things when you're starting, don't be afraid to git reset --hard <ref> / git commit --amend + force push, as long as you know where you're at in history.
The thing is, Git is awesome, but intentionally designed as a low-level and generic tool. Using it correctly for particular workflows (like Git Flow or Github Flow) requires running many Git commands for each operation, and is highly repetitive.
Good developers engineer repetition away. Great developers share what they build. Hence Git Town.
Sure, but a handful of of bash and/or git aliases handles that just fine while also being better suited to a user's particular workflow and easier to learn.
As someone who has engineered repetition away and shares what he builds, I agree, and admire your gumption.
> intentionally designed as a low-level and generic tool.
git is high level. and opinionated. It has branches and tags baked right in. Compare to SVN or CVS where the support is second class.
> requires running many Git commands for each operation, and is highly repetitive.
I run lots of git commands by hand, and can be pretty verbose in commit messages. I (sort of) try to follow this: https://chris.beams.io/posts/git-commit/
However, to speed things up, I will sometimes at shell prompt use `ctrl-r` and search history a bit, then `ctrl-e` to start scrolling in a line brought back up if I want to both 1. see what I committed last, and 2. get a head start on writing the commit message.
I also find the staging workflow git has (another thing I personally consider high-level, purposeful, opinionated to git, and use regularly) to be very convenient. I can type `git status`, `git diff`, `git diff --cached` to see what's staged and unstaged. I can use `git reset` to unstage a file. Overall, I get more granularity on which files I want to add to that commit. This comes in really handing when reverting, merging and rebasing.
So in my workflow, I don't want to give up control of these things.
Apparently, while I don't use these features, `git bisect` and `git blame` also benefit from being thoughtful with commits.
> It shows the Git commands it runs for you, as well as their output.
I am glad to hear that.
> nor does it try to shield you from learning how Git works
This is what irks me. I view git as high level and opinionated already, and have no way of knowing how it would effect someone learning git. I developed my own habits w/ VCS a long time ago.
That said, leave it up to the people who want to try your project.
(I followed you and starred your repository.)
However high level you think it is, it has no opinion on workflows and there's a need for a tool that will automate and enforce git workflows.
I'm not sure if this tool the answer, but there is a need for some sort of tool like this.
I wrote a hacky 'git sync' script at an old company and it achieved what sending a bunch of developers on a course about git did not (it sped up the workflow and cut down on git errors).
Oh really? Staged/Unstaged + Commit + Push to remote+branch. Branches (I suppose you could chuck everything in master), and opt-in or out of tagging.
Maybe users will keep their own remote repositories ("forks")? Even then, it's still pulling in code with the same history that's going to get reconciled via a merge or rebase. Whether it's "forked" to their own repo or in a branch of the "main" repo, it's all the same in the end.
> there's a need for a tool that will automate and enforce git workflows
There's easy, light-weight branching baked right into git.
They scale locally, remotely, and also work with different user's remotes.
You can also merge branches into branches. You can pull --rebase them as well.
> there's a need for a tool that will automate and enforce git workflows.
Beyond branches and remotes?
> I wrote a hacky 'git sync' script at an old company and it achieved what sending a bunch of developers on a course about git did not (it sped up the workflow and cut down on git errors).
Checking out branches and git add/status/diff/commit/push is that time consuming not only would you need to create a shortcut, other devs would opt-in to it?
I use shortcuts for various things in my shell. I have a .gitconfig in my dot-config files (https://github.com/tony/.dot-config). Personal tweaks for coloring and editor settings, a global gitignore. I'm the kind of a guy who picks up shell plugins for fun to try them, but I know that pushing a tool on top of a VCS on colleagues won't go over well.
What did `git sync` do?
Yeah, because most branching and merging in a team setting follows a policy. That branch/merge strategy (and naming) is based upon a whole host of things including testing strategies, release schedules, issue tracker used, code review policies, how much you need bisect, etc.
Git is entirely indifferent to those workflows and is as happy to let you follow it as it is to let you commit and push directly to the master branch with a commit message of "fixed shit".
>Checking out branches and git add/status/diff/commit/push is that time consuming not only would you need to create a shortcut, other devs would opt-in to it?
Yeah, when you add stashing, changing to the correct branches, rebasing and pushing, changing back and unstashing it actually does get tedious, especially since I needed to run it about 20 times a day.
I actually didn't even create the script for them originally, I created it for me and they just started using it.
I've always found this very strange when it's creators don't feel the same way :)
It was built as a low level content addressable filesystem, it's own docs says they weren't even trying to pretend otherwise until version 1.5.
It's only relatively recently (in the scheme of things) it's tried to become higher level.
I'm not sure I'd use this tool, but I'm not going to get upset if people like it.
Use these three git commands you have memorized.
If something breaks ask the person who understands git.
That is the reality. Anything that makes people more productive, especially in contexts where the difference between staged/unstaged and all the other things you mention, don't matter, is very very welcome.
If you're interested in branch aliases, here are some that may be helpful that I use at GitAlias.com.
topic-start = "!f(){ branch=$1; git checkout master; git fetch; git rebase; git checkout -b "$branch" master; };f"
topic-pull = "!f(){ branch=$(git branch-name); git checkout master; git pull; git checkout "$branch"; git rebase master; };f"
topic-push = "!f(){ branch=$(git branch-name); git push --set-upstream origin "$branch"; };f"
topic-finish = "!f(){ branch=$(git branch-name); git checkout master; git branch --delete "$branch"; git push origin ":$branch"; };f"
branch-name = rev-parse --abbrev-ref HEAD
What I like most about using aliases for topic branches (a.k.a. feature branches) is that any team can define its preferred workflow and encapsulate it.
Git Town is a strict superset of your tools. Your "topic start" == "git hack". Your "topic pull" and "topic-push" = "git sync" (you always want to run both anyways). Your "topic-finish" = "git ship".
Want to join forces?
Is this what most people do? And is this something you can turn off with Git Town? I don't like to to squash-merge, I spend time making sure my commits are as much logical and self-contained units as they can be in my branches, and I want to preserve the ability to revert and/or bisect them later.
I would have assumed that a regular (not squashed) merge is more common, and easier to do, because it's the default behavior of "git merge". It takes extra git commands and/or extra non-default arguments to git merge to get a squash merge. My GitHub also doesn't default to squash merge, IIRC... Don't you have to choose squash merge or be told to use it, if you don't otherwise know or care?
My usage is to commit very frequently, like whenever I make a non-trivial fix or small refactor, or when something that touches several files compiles cleanly, or passes a unit test. This is several commits per day. It's practically every file save (if you remember filesystems with explicit version support). So my commit history is very noisy.
When I push back to a shared repo, I want the commit history to document what the change is; various false or partial paths are not enlightening (if I planned to follow strategy 'X', found it did work, and backed out and used algorithm 'Y' then that should go in the source as a comment, not in the metadata.
If my check ins were once a day I might not want to lose them. So I'm philosophically aligned with you, but my commits are so high frequency that the merge functions as a low-pass filter.
I think it would be good if the docs had the git commands that are run for a git-town command.
I prefer aliases i configure myself to understand them, most of my colleges don't even bother with that detail of git commands at all and use an ui.
My best guess is this was a personal project that solved some person(s) problems, and for some reason related to networking or self-promotion, it got the decoration of a full release treatment. What else could cause this?
I know there are zillions of these every day but this seems like one we all can see through. Can anyone share some insight here?
Should I be contributing to the heap of projects like these to further my own career?
Don't fight it: embrace it. Navigating this wasteland is part of your job. A keen eye for separating wheat from chaff is a valuable asset.
Learning to code is only step 1 in learning to program. Learning how to choose your tools, and what to ignore, is just as important.
> comparable to reinventing a wheel
> many projects like this appear to get so much attention and end up on HN
> Can anyone share some insight here?
First the HN audience, its core is hackers and startups. These people have certain problems in common, and they are always on the lookout for ways to eliminate them. The hackers build things and the startup people do a lot of management and they are often one and the same.
Secondly good version control is hard to use across a project without swamping new arrivals or accidentally breaking something. Git isn't good enough, but it is what we have.
So like good hackers we take the first, see the second and try and produce something better. This is how we end up with lots of similar looking projects.
Because they are solving real problems being faced by HN users they get upvoted until the comments discover some fatal flaw (leaky? prevents key conflict resolution?).
This author reckons hes solved it, so he gives it the full treatment because it is worth a lot to have __actually__ solved it. If I could resolve git woes by handing a newbie a ten minute video I would be ecstatic.
Remember, it is important to reinvent the wheel [1] though don't waste time on these projects unless you can see a way through.
Nonetheless, I agree. And if you find it, please share.
I believe source tree shows you the command too if you set it up. Magit is much better than source tree though.
This tool was built to help stay sane in large high-velocity development teams. In such environments, one can easily spend an hour (or so) each day resolving merge conflicts. Feature branches go out of sync with the main development branch multiple times a day. One has to keep pulling, merging, or rebasing all open branches regularly to avoid more merge conflicts later. Those things require running many Git commands.
Git Town makes all of this quick,easy, and bulletproof. A lot of people have been using it for years and love it for that.
Apparently our documentation doesn't get this across well enough. We'll add more details.
It's a set of helpers, that are useful for the author and useful enough to other people that (1) it was upvoted on HN and (2) it has 643 stars on github (so it appears to be fairly popular).
> my understanding is that a user friendly wrapper for such a ubiquitous programming tech with already widespread GUIs and pluins is comparable to reinventing a wheel
Not really. There are many reasons why these functions are not in core git, however for many people these are common tasks and doing it "manually" with git is a chore.
Just like carpenters craft their own jigs and tools all the time, programmers write scripts to automatic repetitive tasks all the time.
> My best guess is this was a personal project that solved some person(s) problems, and for some reason related to networking or self-promotion, it got the decoration of a full release treatment. What else could cause this?
Most Open Source projects start as personal projects that solved some people's problems, and as others found out that it's useful to them they grow in popularity and become "famous" projects.
This one also took the time to make a site, with an introduction, FAQ, etc, while most other projects only have a github page and a small README.
If this project doesn't seem useful to you, don't spend much time trying to figure out what it is. The best is to be goal driven, i.e. you have a project you want to get through (either for work, school or personal project) and you seek projects that might help you doing that.
> Should I be contributing to the heap of projects like these to further my own career?
Don't create projects for the sake of your career, it will only lead to pointless projects boring for you and everyone else. Build what you need to build, what you want to build, and if you think it might be useful for just one other person feel free to post it online. It's not like the size of the Internet is limited and your project will prevent others from existing.
Am I missing something? Does `git merge` imply fourteen other commands?
My concern would be: what happens when the automation encounters and edge case; what kind of unholy mess would you end up with?
And to be fair, with GitHub and GitLab, doing local feature branch merges has become a very rare event for me in the last 5 years.
That's a lot safer than the unholy mess that ensues when most people try to run "git reset --hard" or "git push --force" manually.
Mine were exacerbated by the fact that the bulk of the team didn't really understand git very well, and bouncing between features at a super rapid pace meant I could get into some slightly odd situations. Nothing a bit of git-fu can't fix normally, but can take a little bit of wrangling or forethought.
Git can be intimidating for newcomers. In the last two years, I noticed the pattern that I only use a few essential Git commands in order to resolve a handful of scenarios. I have written them up: https://www.robinwieruch.de/git-essential-commands/ Maybe it helps some people to get started.
* Git Town runs other git commands to inspect the state of things (for example: what is the current branch, are there any uncommitted changes). These are not printed but each one that changes the state (for example: checking out another branch, fetching updates, merging branches) are printed
They all suffer from the same issue: in the face of conflicts they just failsafe to good old git.
I think these tools are good if you want to do something more productively but in the end you will still need to know about git.
But can you use this in practice and not know what git is doing? Aka is this really not a leaky abstraction?
I ask sincerely; having known git for years I can't objectively answer this.
Having a wrapper around another technology or tools to make things easier to use, encapsulates many more important concepts that you have to know as a good developer. I don't think giant tech companies use these kind of tools as well.
They basically take the approach presented here to 11.
I think Git Town is best used only after someone learns Git (and has possibly run through the workflows by hand).
No. Fucking marketing doublespeak. Git is great for source-code management. Don't start your pitch by trying to redefine and reposition Git. You lost me right there.