Status Report: Monitor Files Easily
Everyone has their own frustrations around working with Git. Maybe yours are super advanced frustrations, or maybe they're really basic. @mickymetts recently told me about this frustration: "the little part of - WHERE ARE MY FREAKIN FILES NOW? When are they local, and merging, and branching ..." I have a lot of respect for folks who feel the need to use all caps when gettin' angry at Git. This is a sign of someone who's still fighting, still trying to learn and who's not given up yet. If you're still in all caps mode, you still care, and if you care, it's because you're still trying to figure things out.
Note: I would like to add more to this resource which will include how to find the status of specific files; however, these few tips should be considered part of your essential git toolkit and might just be enough to get you started down a smoother path.
Customize Your Command Prompt
If you're working from the command line, you get ZERO clues about what's going on with your files, until you explicitly ask Git about them. This is tedious to keep having to ask. It's like when you were 8 and sat in the back of the car whining at the driver saying, "are we almost there yet?"
Instead of having to explicitly ask, I've modified my command line
prompt to tell me which branch I currently have checked out and
whether or not I've made changes to any of the files in my
repository. This is a fairly common hack, but every developer
will have their own little quirks on how they implement it.
Searching the web for
bash prompt git status will yield lots
of results. My own prompt is fairly simple, but others have
added a lot more details to their prompt. For example: Show your git status and branch (in color) at the command prompt or local
file status. As
with all things technical: the more you add initially, the more
you'll need to debug if it doesn't work right away.
I found the fancy prompts to actually be quite fussy to set up, and ended up giving up on the really detailed ones. I recommend you too start with something really simple and then add to it if you really need more information. The simple change in colour, along with the name of the branch, actually suits me just fine and is less distracting without all the extra information.
Check the Status of Your Files
Once you've got some kind of indication about the status of your files, you can start asking git for specifics. Assuming you've already adjusted your prompt, you should now get some kind of visual indicator when the branch you're working on is "dirty". This is git slang for "has work which has not been committed to the local repository". To check which files have uncommitted changes, run the command:
Within the output, you'll find information about the corresponding remote branch, untracked files, and tracked files with changes. Here's an example from this page before the file was added to the local repository:
On branch master Your branch is up-to-date with 'origin/master'. Untracked files: (use "git add <file>..." to include in what will be committed) files-status.md nothing added to commit but untracked files present (use "git add" to track)
The second line can be a bit misleading. It currently states that the branch is up-to-date with the remote repository...but it's only showing you the status as of the last time I checked the remote repository. Unlike Twitter and Facebook, command line git is not running in the background collecting status updates from your friends and co-workers.
Update Your Status Updates
To check if there are any changes on the server for the branch you're
working on, you'll need to
fetch the status of the remote
git fetch origin
Assuming everything is up-to-date, you'll get no message back. If there have been new commits in the remote repository, you'll get a message as git downloads the new commits. The Atlassian tutorial on remote repositories does an okay job of explaining git fetch. The article also shows you how to review the new changes you've just downloaded. If you have multiple projects you're working on, you might find GitGot useful. This little app makes it easier to bulk manage all of your local git repositories from the command line.
Use a Branch-Aware Log Browser
Finally, the last little tool I find helpful, is some kind of graph generator for my repository's history. This tool gives me the context of where a change came "from" (are you a branch? is it ahead of another branch in terms of commits?). GUIs for git will give you a much more elegant view of your repository than these tools, but they work just fine for me.
I can either draw the graph at the command line:
git log --oneline --graph
An example of this output would be as follows:
* edcd486 Updated deps. * 05af892 No need for layout anymore. * eb85b12 Merge pull request #11 from stevector/master--implements-spelling |\ | * 086b01e Spelling fix in 2013-02-04-highlight.md * | c5f46bd Merge pull request #10 from stevector/master--fixing-typo-in-readme |\ \ | * | 58e67f4 Spelling fix in README |/ / * | eebb37d Merge pull request #8 from kenjis/fix_url
The dots represent a commit. Anything to the right of the first is (or was) a branch. The branch names are not listed in this output.
Or, I can open up the git browser, gitk, and click around a bit. The git browser is a special add-on which might not be enabled in your version of git. For example: this functionality is not available in the OSX-installed version of git, but it is available in the brew-installed version. To open the browser, use the following command:
If you're working from the command line, it can be a bit of a hassle to find the current status for all of your files.
- Update your prompt to include a git status notification.
- Remember to fetch changes from your remote repository regularly.
- Use a log browser to give you more context of how your branch is doing compared to others.
If you've got more specific questions on how to see the status of a file, ping me on twitter (@emmajanehw), and I'll add them to this resource!