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

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.