As a designer and front end developer, I'm constantly switching between projects and git repositories helping out developers with their front-end code, and sometimes it's easy to commit things to the wrong branch occasionally. At work we use a version of Git Flow, where we push code to 'feature branches', which are then code reviewed and merged to master.
For the most part I use the GitHub desktop client for committing things, as I really like the ease of selecting multiple files and the visual diffs, but sometimes I drop down to the terminal if I screw something up, or want more control.
There's lots more on the web, like a good intro to the basics - this assumes you are already familiar with the terminal and some git basics.
Below are the top 5 git commands I use regularly to get me out of trouble or speeded up my workflow.
git commit -m 'your commit message here' rather than opening up your default editor to add in a message after you run git commit, this lets you specify one on the command line.
git checkout -b my-branch-name this is shorthand as if
git branch was called then a
git checkout was made - useful when you want to quickly create a feature branch.
git checkout - - this is useful to switch to the last repository branch you were in (this works much like the Terminal command
cd - to switch to the last directory you were in).
git commit --amend - opens up your default text editor to amend your last commit message (assuming you haven't pushed up to a remote repo yet).
git reset --soft HEAD^ - if you have just committed something you shouldn't by accident (and haven't yet pushed up to a remote repo), this reverts your repo to the last previous state before your last commit, but importantly keeps your changes and leaves your files in the staging area. Useful if you accidentally commit to master locally when you should have been comitting to a feature branch.
The GIT SCM book is an excellent resource if you need to delve any deeper.
As part of National Blog Post Month (#NaBloPoMo) the spin off from the novel writing month that writers often partake in November, I thought I would try and write a few more quick and short posts for November - lets see how far I can go with this.