Skip to content

Updating Github from Terminal

milaurose edited this page Mar 5, 2021 · 1 revision

Why would you want to do this?

If you're developing a bash script or pipeline, uploading it onto github (even if you're not done working on it) is both useful for others and a good way of keeping track of changes and past versions.

As you edit your script in terminal or atom, you will want to commit your changes to github. This page will explain how to access your github repository form terminal and commit your changes.

The process

Step 1: Clone your github repository

This will make a local copy of all the current scripts in your repository.

From terminal, execute: git clone https://github.com/your_github_account_name/repository_name

Once the repository is created, it will appear as a folder with the same name in your current bash directory, cd into that folder.

Step 2: Create a new branch within the cloned repository

This will be where you can work on your scripts and actively edit them.

Git checkout -b test

This will create a new branch named 'test', and will automatically switch you to this branch. Go ahead and edit your scripts. Any changes that you make to your scripts will remain in this branch, meanwhile your original unedited scripts are still present in the 'Master' branch.

To switch back to the master branch: git checkout master

To double check which branch you are currently in: git status This will also tell you whether your branches are up to date with the master branch, or whether changes have been made.

Step 3: Track the changes that you want to commit

This will specify which of the edited files, you actually want to commit. git add filename

To add all the files in the folder: git add -A

Step 4: Perform the commit

After committing, the tracked files will only be visible on the test branch, and will no longer be visible on the master. They have now become a permanent part of the test branch, and there original version no longer exists (at least not in the local repository). git commit -m “Description of changes made”

Adding a description of the changes will make it easy for others, and for your future self to figure out where bugs appeared and locate a desired past version of the script.

Step 5: Push the changes from your local computer to your online github account

Now the 'test' branch will appear on your online account.

git push origin name_of_branch

Step 6: Merge the 'test' branch with your 'master' branch

Do this online on your github account after you are convinced that you want your changes to become part of the main script. If you are working with collaborators, they may review the changes before agreeing to merge the branches.

How often should you commit your changes?

There is no correct answer for this. It would be inefficient to perform a commit every time that you make a minor change. In general, it is useful to perform a commit when you make multiple adjustments that all fall under the same purpose.

Clone this wiki locally