Email Subscription Form

Saturday, May 11, 2019

A Gentle Introduction to Git

For a software tester who has just started writing test automation, using version control software such as Git can seem daunting and confusing.  But being able to pull down the latest code, update it, and submit a pull request is very important for any team project!  In this week's post, I'll provide a gentle introduction to the basics of Git.

What is Git?

Git is a version control system.  A version control system is a system that allows a group of people to collaborate on code without accidentally overwriting each other's work.  It also allows the group to keep track of who changed the code and when it was changed, so it's easy to trace back to the source of a problem.

Why is Git needed?

Consider what file editing is like when you don't use a version control system.  Let's say you have a recipe for brownies.  You send the recipe to your friend, and he decides to change the amount of cocoa in the recipe.  When he makes that change, it is only in his version of the file, not yours.  Your files are now different.  If you make a change to add more vanilla to the recipe, now your versions have diverged even further. 

You can see how this would be unacceptable for software code!  In a version control system, there is one "master version" which is the accepted version of the code.  This master version lives in GitHub (or another version control hosting service), and can be "pulled" down by any user.  When someone wants to make a change to the code, they pull down the master version of the code, create a "branch" that is a copy of the master version, make their changes to the branch, push the branch up to GitHub, and then do a "pull request", which is asking for someone to review their code and merge it into the master branch.

Confused?  Don't worry, this will look much simpler with an example.  Let's imagine that we have a source code repository called "The Thinking Tester Guestbook".  We'll take a look at what would happen if Prunella Prunewhip wanted to add her name to the guestbook.

These instructions assume that Prunella has already installed Git on her computer, and has already created a GitHub account.)


Step One: Prunella clones the source code repository

This is often called "cloning the repo" or "pulling down the repo".  Prunella does this by going to the URL in GitHub that has the source code, and clicking the green "Clone or download" button.  A dropdown appears with the URL she will need to clone the source code.  She clicks the little clipboard button to the right of the URL to copy the URL text.

Prunella opens up a command window and navigates to the folder where she would like put the source code.  Once she's there, she types git clone and then pastes the URL text next to those words.  The repository is copied from GitHub into a new folder.

Now that the repository is in a folder on her computer, she can open the folder up in her file browser and take a look at what's in there.  She sees that there is one text file, called "guestBook.txt".  The text file reads:

Kristin Jackvony was here on May 11, 2019

Step Two: Prunella makes a new branch and adds her changes to that branch

Before Prunella makes any changes to guestBook.txt, she should create a new branch and switch to it.  So in the command line, she navigates to the new folder that was cloned earlier by typing
cd ThinkingTesterGuestBook.

She can verify that she's in the master branch by typing git status, and she will get a response like this: On branch master.

Now she can create a new branch and switch to it by typing git checkout -b NewEntry.  The command "-b" tells Git to create a new branch.  "NewEntry" is what Prunella has chosen to name her branch.  And the command "checkout" is what causes Git to switch to the new branch.

If Prunella types git status at this point, she will get On branch NewEntry as a response.

Now that Prunella is in the correct branch, she's going to make a change to the guestBook.txt file, by adding one line, so that the file now reads:

Kristin Jackvony was here on May 11, 2019
Prunella Prunewhip was here on May 13, 2019

Step Three: Prunella commits her changes and pushes them to GitHub

Now that Prunella has made the change she wanted, she needs to commit and push her change.  First, she can run git status and she'll get this response: 

On branch NewEntry
modified: guestBook.txt

This shows that the guestBook.txt file has been modified. Next, Prunella needs to add the file to the commit, by typing git add guestBook.txt.  Now if she types git status, she'll see this response:

On branch NewEntry
Changes to be committed:
     modified: guestBook.txt

Next, Prunella commits her change by typing git commit -m "Adding a new entry".  The "-m" in this command stands for "message".  The "Adding a new entry" text is the message that she is adding to explain what she is committing.  The command line will respond with how many files and lines were changed.

Once the change has been committed, Prunella can push the change up to the GitHub repository by typing git push origin NewEntry.  The "NewEntry" value explains that the code should go up to the NewEntry branch, which doesn't exist yet in the GitHub repository, but it will be created with this command.  "Origin" refers to the GitHub repository (this is also referred to as "remote").  The command line will respond with several lines, the final line of which will be
* [new branch] NewEntry -> NewEntry, which shows that a new branch called NewEntry has been created in the origin, and that it was copied from the local branch Prunella created, which was also called NewEntry.

Step Four: Prunella creates a pull request in GitHub

Now that her new branch has been pushed up to GitHub, Prunella can submit a pull request to ask that her changes are merged with the master branch.  She does this by going to the GitHub repository and clicking the "New Pull Request" button.  This takes her to the "Compare" page.  She makes sure that the left side of the comparison is the master branch, and then she chooses the NewEntry branch from the branch dropdown.  She can see how the guestBook.txt file has changed; the new line she added is highlighted in green, illustrating the difference between the two files.  (If she had deleted a line, the line she removed would be highlighted in red.)  Finally, she clicks the "Create Pull Request" button.

Step Five: Prunella's pull request is approved and merged

The final step in the file change process is that the owner of the repository (or any teammates who have approval permissions) will review the change, approve it, and merge it.  Now if Prunella changes to the master branch by doing git checkout master, pulls down the changes by doing git pull origin master, and takes a look at guestBook.txt file, she will see that her entry has been added:

Kristin Jackvony was here on May 11, 2019
Prunella Prunewhip was here on May 13, 2019

And that's all there is to it!  In my next post, I'll add a few more Git tips and tricks, but these steps should be enough to get you started with committing your own code to your team's repository.

46 comments:

  1. This is a great intro for GIT. Thanks a lot.

    ReplyDelete
  2. Detailed explanation. Thank you so much.

    ReplyDelete
  3. Thanks for Sharing.
    It's great to be here and to learn more about software testing.
    Software testing training and placement in chennai

    ReplyDelete
  4. Thanks for the marvelous posting! I definitely really liked every piece of it and I also have bookmarked it to check out new things on your site.

    Visit: Automated Time Tracking Software

    ReplyDelete
  5. If you are experiencing quickbook error problems with your system, this article is for you. It contains every detail regarding quickbooks error code 6147 as well as probable symptoms and causes.

    ReplyDelete
  6. If you do work related to accounts you must have heard that QuickBooks is well-known accounting software so QuickBooks connection diagnostic tool is a very valuable tool. Here are some of the advantages of utilizing QuickBooks connection diagnostic tool.
    During the installation procedure, this programmed can diagnose QuickBooks issues. It also assists users in resolving numerous issues.
    It saves consumers a lot of time and effort by simplifying the error-resolution process. It also aids in the correction of unanticipated and multi-user mistakes in QuickBooks desktop.

    ReplyDelete
  7. The problem 6175, 0 quickbooks error code 6147 0 is most commonly caused by incorrectly adjusted settings or installed apps. You may receive an error message while dealing with the problem, and it frequently receives bad feedback as a result of faults and issues. Some faults are extremely difficult to correct. Continue reading to learn how to use QuickBooks with ease once more.

    ReplyDelete
  8. how To unmatch a transaction in QuickBooks online there are two ways To know the process of how to unmatch a transaction in QuickBooks online read the blog To Know more and check also How To Track Mileage in QuickBooks Online or gear icon in QuickBooks

    ReplyDelete
  9. As the QuickBooks online enterprise expands, it makes sense that they need to grow their library of QuickBooks file extensionsto accommodate the big data. QuickBooks Desktop uses different file types to express varying forms of information. For example, your main company files (QBW) are in a whole other realm than the backup data files (QBB).

    ReplyDelete
  10. Why QuickBooks Desktop Overflow error occour?
    There are several possible causes why overflow occurs: An account balance or other field in your company file has an amount greater than $9,999,999,999,999.99. The format you are copying from an Excel spreadsheet does not match a format that is accepted by QuickBooks

    ReplyDelete
  11. The first thing you should know is that QuickBooks Enterprise is not updated like a traditional software program. There are no updates that are announced to users on the internet, so you will have to contact the company directly in order to request an update. for more information visit here quickbooks not update

    ReplyDelete

  12. Thanks a lot for sharing this information. Your content is amazing hope for getting more content like this in future. I also write blogs my last blog is QuickBooks Hosting Mode is Off.

    ReplyDelete
  13. Very appreciated. Information if you are experiencing some QuickBooks Issue then just call at our team
    +1 855-977-3297

    ReplyDelete
  14. If you are looking quick assistance from QuickBooks then just dial our team at
    QuickBooks Customer Service 1 855-729-7482

    ReplyDelete
  15. Quickbooks Customer Service Expert Team Give you quick solution According to your problems You can easily connect by dialing+1 855-675-3194 to get solution

    ReplyDelete
  16. Thanks for sharing this wonderful post with us. Quickbooks is one of the most used accounting programs in the world. For all your accounting needs, you can reach QuickBooks at quickbooks customer service+1 855-977-3297

    ReplyDelete
  17. QuickBooks is an easy-to-use tool for businesses at is used to record and process accounting operations like account payable, account receivable or other task. if you have facing some problems then you can click on quickbooks customer service+18554287237

    ReplyDelete
  18. Your Content is very appreciated and useful If you're Searching online answer about your Quickbooks Software so you contact Quickbooks Customer Support +1 877-755-5046

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Are you looking help for Quickbooks Issue? you need to dial Quickbooks Customer Supporte: +1 267-773-4333 to get any help

    ReplyDelete
  21. QuickBooks is an accounting software used that helps you with your finances.If you have a question about your Quickbooks account, please contact
    Quickbooks Customer Support+18553777767

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. This comment has been removed by the author.

    ReplyDelete
  24. If you are looking Quickbooks correctable errors or issues on your desktop,Get answers to all of your Quickbooks questions Quickbooks Customer Support

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. Very Great Content If you looking online Help with QuickBooks For Your Business dial
    Quickbooks Customer Support +17735165910 5141 Doral, FL, United Statesand talk to with a live representative

    ReplyDelete
  27. Very Nice informations !! You can contact
    Quickbooks Customer Support +1 267-773-4333

    ReplyDelete
  28. By dialling Quickbooks Customer Service +1 347-982-0046 you will be connect our team who will solved your solutions quickly

    ReplyDelete
  29. Great Article ! If you are Interested working with QuickBooks Software then you connect with our team QuickBooks customer service + 1 877-755-5046 to solve any QuickBooks Issue

    ReplyDelete
  30. If you are looking for advice and assistance troubleshooting issues with QuickBooks Desktop, Dialing QuickBooks Customer Support Phone Number : +1 855-941-1563 to get instant help

    ReplyDelete
  31. If you want to know about the system Just call QuickBooks customer service at
    QuickBooks Customer Service +17577510347 or talk to them live on their website.

    ReplyDelete
  32. This problem typically occurs when you try to open a business file. Your computer's screen will display a notice box informing you of the mistake. You might not be able to access your corporate file because of it. You can read this to learn about the most effective ways to resolve QuickBooks error 6000.

    ReplyDelete
  33. Do you bump into the QuickBooks Error Code 1638? Well, don’t worry about this glitch anymore, as we have got your back. This is a common technical bug that arises in QuickBooks when another version of QuickBooks is already installed on your computer. When this error occurs, it appears with a warning message on the screen stating: Another version of this product is already installed. This message is an indication error 1638. In this blog, we are going to provide you a detailed information on its causes and resolutions to troubleshoot it. Stick around this blog to learn about this issue till the end.

    ReplyDelete
  34. Are you wondering how to fix the QuickBooks Compile Error in the Hidden Module? Well, before diving into its resolution let’s go through some important information about this error. Compile error generally takes place when a user tries to export client-ready payroll reports in the QuickBooks. This error appears without being noticed and a notification message comes as the action is being done. This error is associated with issues in company files. The feature Client Ready Reports in QuickBooks is a feature that helps in sharing reports with clients. Compile error while using this feature and in most cases, it appears when MS Excel and QuickBooks clashes. It may happen due to incompatibility issues.

    ReplyDelete
  35. Now that you know the correct set of steps to Delete a Journal Entry in QuickBooks you can delete a wrong entry entered mistakenly. Above-mentioned steps will help you in deleting the journal entries in both QuickBooks Online as well as QuickBooks Desktop and MAC. However, in case you need a helping hand to implement these steps or got stuck somewhere you can contact our support team for instant assistance.

    ReplyDelete
  36. QuickBooks Direct Deposit Form is the most effective and easiest way to pay your employees. Writing off paychecks and handwriting daily takes much time and effort. But,by using direct deposit forms you can save writing time and loaded activities. It is convenient for employers as they can collect employee information, bank information and essential authorization to manage payroll.

    ReplyDelete

New Blog Location!

I've moved!  I've really enjoyed using Blogger for my blog, but it didn't integrate with my website in the way I wanted.  So I...