Git commands we use most often

Some basic Git commands that we frequently use here at Tosbourn Ltd.

We use Git for source control here at Tosbourn and here are some of the commands we use on a regular basis which help us when tracking changes to our code.

Git add

Used for adding file contents to the index.

git add . allows you to add all changes to all files.

git add app/models/article.rb adds a single file.

Git commit

git commit -m 'Adds copy to home page' This commits the code which allows us to record changes to our repository. The -m flag allows us to add a message to the commit, which we follow with the message in quotes.

You can also set up your favourite text editors/IDEs to open when you type git commit.

Git push

git push origin name-of-branch will push changes from your local machine to wherever you have your code hosted i.e. GitHub. origin refers to the online repository store so in some cases this might be something else like staging or development depending on how you team may have set things up.

Git pull

git pull will pull changes down from your online repository to your local machine.

Git branch

git checkout allows you to switch between branches. To checkout your main branch you would type git checkout main. To create a new branch you would type git checkout -b new-branch-name.

Git diff

git diff allows you to view changes between the original code (the branch you branched off) and the new changes that you have made to the code.

Recent posts View all

Web DevProductivity

Keeping on top of website updates

Learn what website updates are, what they entail, why they are important, and how we can help

Freelancing

Getting the most out of your agency

Here are some tips based on years of working with, for, and as an agency on how to get the most out of any work you do.