Working with repositories

Let's get our hands dirty!

If you are reading this book, you are probably a programmer, as I am. Using a programming language and its source and binary files to exercise could be fine. However, I don't want to distract you from understanding a language you probably don't use every day. So, let's settle things once and for all. When needed, I will use a nice markup language called Markdown (see http://daringfireball.net/projects/markdown/).

Apart from being simple yet powerful, Markdown silently became the favorite choice while typing readme files (for example, GitHub uses it extensively) or comments in forums or other online discussion places, such as StackOverflow. Mastering it is not our goal, but to be able to do the basic things is surely a skill that can be useful in the future.

Before you proceed, create a new folder for exercises, for example, C:ReposExercises. We will use different folders for different exercises.

Unstaging a file

Consider the following scenario. You are in a new repository located in C:ReposExercisesCh1-1. The working directory actually contains two files: first.txt and second.txt. You have accidentally put both first.txt and second.txt in the staging area, while you actually want to only commit first.txt. So, now:

  • Remove the second.txt file from the index
  • Commit the changes

The result of this is that only first.txt will be a part of the commit.

Follow these simple steps to solve this simple task:

  1. Create the C:ReposExercisesCh1-1 folder and open Bash inside it.
  2. Use the git init command on the repository as we learned.
  3. Create the first.txt and second.txt files and add them to the staging area, as shown in the following screenshot:
    Unstaging a file

At this point, remove the second.txt file and commit. This time, try to use the handy git rm --cached command, as suggested here:

Unstaging a file

Well done!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset