Joshua Hibbert

Latest Post

Some Useful Git Tips and Commands

This post will take to read.

Git can be overwhelming when you’re first starting out, but it’s an incredibly powerful tool that should be a part of every web developer’s workflow. In this post, I’ll outline some resources that will help you better understand and use Git.

Getting to know Git

I’m a fan of learning by doing, so I would definitely recommend setting Git up on your computer and creating a test repository to experiment with (if you’re not already using it). As some of the commands are quite technical, it’s also worth checking out the tutorials that have been release by Code School (particularly good) and Codecademy.

Commonly Used Git Commands

As Git commands aren’t always that intuitive, I’ve created a list of the commands that I find myself using a reasonable amount. That way I can simply reference this list instead of having to search for the correct way to run a command.

View Commands on GitHub

Setting Up Aliases

Aliases are a big time saver for me when using Git. They allow me to quickly enter commands without having to type them fully. They can be implemented no matter the operating system you’re using, but if your command-line interface supports aliases then you can create even more powerful alias functions. Here is an article outlining how to set up aliases, and the aliases I use can be viewed below.

# Git Aliases

alias get='git '
alias gut='git '
alias got='git '
alias g='git '
alias gi='git init '
alias gs='git status -sb '
alias ga='git add '
alias gc='git commit -m '
alias gac='ga -A && gc '
alias gp='git push '
alias gpo='git push origin '
alias gpom='git push origin master'
alias gr='git rm -r '
alias gb='git checkout -b '
alias gc-='git checkout - '
alias gd='git diff '

function gcl {
  git clone ssh://$1/$2.git;

function gacp {
  git add -A;
  git commit -m "$1";
  git push origin $2;

Note: Use the functions by writing the function name followed by the relevant text for $1 and $2 (e.g. gcl joshnh Git-Commands)

View Aliases on GitHub

Some Usage Tips

Finally, here are some usage tips that will help minimise any issues that might arise:

  • Commit your changes often and accurately describe what has changed. This ensures that if you’re looking for a specific commit in the future you’ll be able to easily find it. The way I do this is to imagine I’m writing my commit as someone else; how much detail would I want them to include so I can easily tell what has changed?
  • Make use of branches when working on specific features. This is useful when working with others and helps you make changes without impacting existing code.
  • Pull regularly, especially when working on a project with other people. This will help minimise any merge issues that might arise when you merge a branch you’ve been working on with a master branch.
  • If you get stuck when using Git via the command line, make use of git [command] -h. Git’s native help is often enough to save you having to search online for a solution.
  • If you don’t want all files in a project to be tracked using version control then make use of Git’s .gitignore file.
  • When working with others, use git blame [filename] to see who authored each line (also when it was edited and in which commit).

Latest Work

Hire Me

Latest Projects