Skip to content

Committing Work

TLDR

Pre-requisites
Pre-requisite Importance Note
Intro to Git Necessary This guide assumes you are using Git to version control
Using Git collaboratively Helpful Get started using Git as a team

What is a Git commit?

Git commits are the core building blocks of a Git repository's history. Commits can be thought of as snapshots or checkpoints along the timeline of a project.

Adding commits keeps track of your changes and progress as you work and each commit is a point in the project you can always go back to if anything goes wrong.

Snapshots are always committed to the local repository. Git doesn’t force you to interact with the remote repository until you’re ready.

How to make a Git commit

To change your working directory to the project directory, open a terminal (e.g. Bash Terminal) and enter:

cd <project-filepath>

To initialise a Git repository for the project, in a terminal enter:

git init

To clone an existing Git repository, open a terminal (e.g. Bash Terminal) and enter:

git clone <url>

Make changes

Here is an example of creating a new README markdown file using the terminal:

echo "# Name of Repository" >> README.md

Stage files

To add untracked or modified files to the staging area, in a terminal enter:

git add <file-name>

Warning

You can also use git add . to add all the files that have changed - but use this with care - it's best practice to manually confirm each change to ensure it was intentional

Info

It is possible to skip the staging process and commit a file directly.

However, this is generally NOT recommended.

To find out more about why using "git add" is important, see this great guide by Github

Commit files

To commit all staged files, in a terminal enter:

git commit -m "Added README"

Useful commands

  • Check which files have changed in a repository: git status
  • Check the history of commits: git log

Info

You can escape from git log by pressing q


Last update: March 1, 2024
External Links Disclaimer

NHS England makes every effort to ensure that external links are accurate, up to date and relevant, however we cannot take responsibility for pages maintained by external providers.

NHS England is not affiliated with any of the websites or companies in the links to external websites.

If you come across any external links that do not work, we would be grateful if you could report them by raising an issue on our RAP Community of Practice GitHub.