
$~/P/b/s/my_app (abk/new-feature-branch)> git branch Switched to a new branch 'abk/new-feature-branch' $~/P/b/s/my_app (abk/old-feature-branch)> git checkout -b abk/new-feature-branch
Git status short how to#
I can't describe it any better than Chris Jones his classic post, How to Fix Your Git Branches After a Rebase. This isn't something I use every day, but when I need to get a branch up to date after things have been moving around, it's perfect. What's nice about this is that I don't have to type the name of my feature branch, so this is the same every time and has become muscle memory. $ git rebase - # instead of git rebase main $ git checkout - # instead of git checkout feature-branch My most common use case for this is when I'm on a branch, let's call it "feature-branch," and want to rebase with main: $ git checkout main

So if I'm hopping between two branches, this saves a lot of typing. The - refers to the last branch I had checked out. You can get some really lovely output with the -pretty option, but this is almost always good enough for me since it provides a quick list of recent commits without too much extra info. I find that git log takes up too much space, so most of the time I use this when I want to see what's been going on recently. The "3" above can be replaced with any positive integer, depending on how many commits I want to work with. My local commit messages are often notes to myself, like "tests passing but need to refactor database queries" or "created model and migration, do routes next." To get my work ready for a pull request, I do an interactive rebase to combine commits, reorder commits, and rewrite my commit messages so they are in line with project standards and useful for other developers. I commit a lot while I'm working but like to leave a clean history before I open a pull request. It won't automatically catch untracked files, so if I've added anything brand new, I'll run git add -N. It helps me catch typos, errant debugging statements, or other mistakes. I use this almost exclusively when staging since I like to review my changes before I commit them.

If you, like me, pretty much always want to see things this way, you can make this setting your default by opening your git config file with $ git config -global -edit and adding this: Īfter that, git branch will always show your most recently used branches at the top. This lists branches in order of recent activity instead of alphabetically.
