Branching, Places, and GUIs
In this chapter, you will learn about the crucial "five places" for Git: the work area, the index, the local repository, the remote repository, and the stash. You will see how to use each of these and how they work together.
Each concept will be illustrated with both code and screenshots, and most Git actions will be illustrated in the command line, Visual Studio, and a GUI (GitHub Desktop).
You'll also learn about creating branches, committing code, and how to move commits from the work area to the repository, and from the repository to the remote repository.
- The work area
- The index (staging area)
- The local repository
- The remote repository
- The stash
Let's begin by examining each of these in turn.
The work area
The work area is where your current files are. That is, if you were to open Windows Explorer and navigate to the directory you cloned to, you would see the version of the program you were currently working on. If you were to open Visual Studio 2019, these are the files that would be in the Solution Explorer. Again, the work area is where your current files are; if you open Visual Studio on your project, the files in the work area are what you will see. As you change branches (see below) the work area is updated with the appropriate files. This can be one of the hardest concepts in Git: when you change branches you change the files that are in your work area – that is, the files for that branch...
Using branches is critical to working with Git, not to mention to the success of your project. The idea is this: you have a "main" branch that you'll do your releases from. Each time code is added to the main branch it is checked and reviewed so that the main branch stays as clean as possible.
When you want to work on a bug or a feature, you create a new branch (often called a feature branch). This creates a copy of the code that is currently in the main branch. You can work on your feature branch without affecting the main branch at all. Once you are done, and all is working, you can then "merge" your feature branch into the main branch:
Figure 3.11: First feature branch
Notice that there is a pointer named Head. This points to whatever is in your work area. In this case, we've branched to Feature 1 and Head shows that the code for that feature branch is now in our work area.
That is a pretty good simplification of branching...
In this chapter, you have learned about the crucial "five places" for Git: the work area, the index, the local repository, the remote repository, and the stash. You have seen how to use each of these and how they work together.
Each concept was illustrated with both code and screenshots, and every Git action was illustrated in the command line, Visual Studio, and GitHub Desktop.
Finally, you have learned about creating branches, committing code, and how to move commits from the work area to the repository and from the repository to the remote repository.
Create a private repository on GitHub named
Contacts, and then clone that repository down to a folder on your disk. Using the command line, create a feature branch named
Person and in that feature branch, create a person object with their name, age, and social security number. Create commits as you add each attribute. Review the log to see what you've created and then add these commits to the remote repository.
There is no one right way to do this, but we'll walk through a likely answer.
Task #1 – create a private repository on GitHub named
Contacts. To do this, open a browser to Github.com and navigate to your repository page. Click on New and fill in the fields as shown here:
Figure 3.32: New repo on server
Notice that I've marked the repository as private. Click the Create Repository button.
Task #2 – clone that repository down to a folder on your disk.
On the same GitHub page, click on Code and click on the clipboard to copy the HTTPS or SSH path (if you have SSH you'll know it, otherwise choose HTTPS):
Figure 3.33: Copy address from server
Open the command line where you want your cloned repo and type:
and paste in the link you just copied:
git clone [email protected]:JesseLiberty/Contacts.git
You should see something like this:
Figure 3.34: Cloning from server to local repo...