Skip to content

5. Editing and Adding Files

George Robertson edited this page Nov 29, 2019 · 7 revisions

The following instructions show you how to use Git to make any editions to files already in the repository or how to add a new file to the repository.

  1. Checkout or create a new branch using GitBash depending on the type of work you are doing. If you are unsure whether to use an existing branch or create a new one then email codon.library@nhs.net.

If checking out an existing branch, use the following command to ensure your version of this branch is up to date. You should also do this at regular intervals if more than one person is working on the same branch.

`git pull`

git-pull

  1. Follow instruction 2a or 2b depending on whether you are editing an existing file, or adding a new file.

If editing a file:

a) Open the file you wish to edit in your chosen editor e.g. notepad, VS code etc. Edit the file (ensuring any code complies with codon style guides) and then save it.

If adding a new file:

b) Copy the file (ensuring any code complies with codon style guides) to wherever you have cloned the repository on your local machine, ensuring the file is in the correct folder.

  1. Check the status of the branch you made the changes to using the following command

    git status

This will show tracked file/changes (marked in green) and untracked files/changes (in red). You should be expecting untracked files/changes if you have recently made them.

  1. Stage any changes you have made by typing the following into GitBash:

    git add <name_of_file> .

    or

    git add --patch

Please read the Git Cheat Sheet for clarification on the differences

git-add

  1. Commit those changes using the following command. Your <commit message> should be concise and descriptive of the changes you have made e.g. added suppression function, fixed typo and should include the name of file/files that you have changed/added.

    git commit -m "<commit message>"

Example-commit

  1. Push your changes to your local copy of the repository by typing the following command into GitBash. You may be asked to sign into GitHub at this point.

    git push

git-push

Any changes you made will now be visible on your clone of the repository on your GitHub account. We suggest only committing changes once you are happy with them, rather than committing an unfinished piece of work several times. In this scenario you should stage several changes (instruction 3), then commit them all once you are happy.

These changes will still only be visible to your forked version of the repository. You must then request to merge these changes into the codonPython repository by submitting a pull request. Instructions on doing this can be found here.