Skip to content
PatiGenius edited this page Mar 16, 2021 · 1 revision

Git HandsOn - Exercise 1

In this wiki we can find some information about how getting started in git:

  • we show how to create a new branch a part from the master one
  • we upload a python script to the repository in which we are working
  • we learn how to merge branches and move from one to another
  • we stage and commit changes locally in our repository
  • we push the changes remotely in our Github repository

We work with a virtual machine and we create a repository called git_HandsOn which contains a README.md file and a script from python seqClass.py. We are working on a master branch and we are going to define new steps from this point.


Making a new branch called fix and moving to it

We create a new branch and move frome the master one to it. For this, we use the next code:

git branch fix: to create the new branch.

git checkout fix: to move from the master branch to the fix branch.

git branch: this instruction allows us to see how different branches we have.

Branches

Fixing the seqClass.py script so that it is able to classify correctly any RNA or DNA sequence

To fix the seqClass.py we just need to access to the script content and modify some parts of code in orer to obtain what we want. We do so by coding the next lines:

nano seqClass.py: we access to the content of the script and change what we need.

git add seqClass.py: we add the changes that we have made in the stagin area.

git commit -m "Fix script to correctly classify RNA and DNA in the fix branch": we commit the changes and summarize the main idea of this commit.

commits

Merging the fix branch back to master

To merge two branches and introduce the changes of branch A to branch B, first we need to be located to the main branch in which we want to have the commits uploaded. So, what we need to do is to move again to the master branch and then we can merge it with the fix branch. This way, we can add the changes from fix to master.

git checkout master: we move to master branch

git merge fix: we add the changes from fix to master branch

Adding comments to explain the changes

We can access to the recent comment from the last commit and we can see that is the one defined in the fix branch when fixing the changes in the script. Now, we can see it in the master branch because we have merged both branches. We change this explaination to a new one.

First, to check the commit history we can use the next instruction:

git log: access the commit history

CommitFix

Now, we change the comment:

git commit --amend -m "Merging information from fix branch to master branch": we change the comment of the more recent commit. Now we can define the las commit as the merging step.

CommitNew

Pushing the commits on master and fix branch to the Github repository

We may transfer the commits from the local repository to the remote one by using the next code:

git push origin master: to transfer commits from the master branch

git push origin fix: to transfer commits from the fix branch

At last, we may see in our github the following:

FinalBranches