Committing Work
TLDR
- This is a beginner friendly guide on how to commit your work using Git for the first time!
- Commits can be thought of snapshots or checkpoints along the timeline of your project that you can go back to if anything goes wrong.
- Initialise or clone a Git repository with the
git init
orgit clone
command. - Make changes.
- Stage changed files with the
git add
command. - Commit staged files with the
git commit
command.
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:
To initialise a Git repository for the project, in a terminal enter:
To clone an existing Git repository, open a terminal (e.g. Bash Terminal) and enter:
Make changes
Here is an example of creating a new README markdown file using the terminal:
Stage files
To add untracked or modified files to the staging area, in a terminal enter:
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:
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
Useful links
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.