Lab1-Version Controlling with Git in Visual Studio Code and GitHub
Lab1-Version Controlling with Git in Visual Studio Code and GitHub
Overview
Git is a distributed version control system. Git repositories can live locally (such as on
a developer’s machine). Each developer has a copy of the source repository on their
dev machine. Developers can commit each set of changes on their dev machine and
perform version control operations such as history and compare without a network
connection.
In this lab, you will learn how to clone an existing Git repository from GitHub. In
addition, you will learn about Git branching and merging support. You will use Visual
Studio Code, but the same processes apply for using any Git-compatible client with
GitHub.
Prerequisites
1. Open Visual Studio Code. In this task, you will configure a Git credential
helper to securely store the Git credentials used to communicate with GitHub.
If you have already configured a credential helper and Git identity, you can
skip to the next task.
2.
1. Your GitHub browser tab should now be open to your forked version of the
repo.
2. Getting a local copy of a Git repo is called “cloning”. Every mainstream
development tool supports this and will be able to connect to GitHub to pull
down the latest source to work with. From the Clone or download dropdown,
click the Copy to clipboard button.
What’s in a commit?
The file(s) changed in the commit. Git keeps the contents of all file changes in
your repo in the commits. This keeps it fast and allows intelligent merging.
A reference to the parent commit(s). Git manages your code history using
these references.
A message describing a commit. You give this message to Git when you create
the commit. It’s a good idea to keep this message descriptive, but to the point.
3. Select the Source Control tab to see the one change to the solution.
6. Click the Synchronize Changes button to synchronize your changes with the
server. Confirm the sync if prompted.
Staging changes allows you to selectively add certain files to a commit while passing
over the changes made in other files.
5. From the Source Control tab, click the Stage Changes button
for CartItem.cs.
Git’s use of the Branches and Merges feature works through pull requests, so the
commit history of your development doesn’t necessarily form a straight,
chronological line. When you use history to compare versions, think in terms of file
changes between two commits instead of file changes between two points in time. A
recent change to a file in the master branch may have come from a commit created
two weeks ago in a feature branch but was only merged yesterday.
1. Switch to the GitHub browser tab. You can review the latest commits on
GitHub under the Commits tab.
2. The recent commits should be right at the top. Click the most recent one.
3. This view enables you to review the changes applied by this commit.
Click View file.
4. Click History to track the commits made to this file over time.
5. Click the Browse repository at this point in the history button for the
second commit. This was the first commit pushed from this lab.
6. You can now review the state of the repo at the time this commit was pushed.
The dropdown at the top provides a convenient way to switch between
branches as well.
Committing changes to a branch will not affect other branches, and you can share
branches with others without having to merge the changes into the main project. You
can also create new branches to isolate changes for a feature or a bug fix from your
master branch and other work. Since the branches are lightweight, switching
between branches is quick and easy. Git does not create multiple copies of your
source when working with branches, but rather uses the history information stored in
commits to recreate the files on a branch when you start working on it.
4. Enter the name “dev” for the new branch and press Enter.
Git keeps track of which branch you are working on and makes sure that when you
checkout a branch your files match the most recent commit on the branch. Branches
let you work with multiple versions of the source code in the same local Git repository
at the same time. You can use Visual Studio Code to publish, check out, and delete
branches.
6. Note that there are two dev branches listed. The local (dev) branch is there
because it’s not deleted when the server branch is deleted. The server
(origin/dev) is there because it hasn’t been pruned. Select
the master branch to check it out.
11. Note that the local dev branch is gone, but the remote origin/dev is still
showing.
14.
15. Note that if you don’t see the Git logs in the output console, you may need to
select Git as the source.
16. Click the master branch.
1. Return to the GitHub browser tab and navigate to the Branches tab.
3. However, maybe we should keep it around for a little longer. Click Restore to
undo the delete.
1. While it may not seem like much, the product team has decided that this
version of the site is exactly what’s needed for v1.1. In order to mark it as
such, return to the Code tab and select Releases.
2. Click Create a new release.
4. You have now tagged the project at this release. You could tag commits for a
variety of reasons, and GitHub offers the flexibility to edit and delete them, as
well as manage their permissions.
5. Select the Tags option to review tags by name.
4. Enter the full repo name and click the option to delete the repository.