Using Git

In this section you will find information on how to use Git version management system in Visual Studio. It is possible to manage Git through command prompt, a desktop GUI version, or version control integrated into another IDE (such as PyCharm), but since we will be programming with Visual Studio, we are going to use the VS plugin.

What is Git?

Git is a version control system that helps software developers maintain backups and keep track of changes made to their projects. Essentially, it automates the process of copying backup versions of your projects to new locations. It also allows users to work on the same project from multiple locations, and multiple people to collaborate on the same project.

Here is the official website:

There is a lot more that it does, but we are just going to learn the basics for our purposes.

Is GitHub the same thing?

No. GitHub is simply a website that allows you to remotely store your projects using the Git system, so that it is easy for you to access them from any computer with an internet connection. It also makes it easy for multiple people to collaborate on a project at the same time. Oh, and it is free. GitHub is not the only free online Git repository, but is one of the more popular ones. It has also been integrated into Visual Studio.

We will use the Git system on the local version of our project, and store a remote copy of our projects on GitHub so that we have an extra backup. Through GitHub you can easily retrieve (clone) your projects from any computer in which you have internet access. It will also allow you to keep your projects long term, and share them with anyone you wish.

Go to GitHub, and create an account.

https://github.com/

There is a ton of information and countless tutorials on how to use Git. Feel free to learn more on your own. We are only going to use Git and GitHub through Visual Studio Community 2019 in this course, but many people prefer the command line interface that you can use in a PowerShell or terminal if you are on a Linux machine.

Tutorials

Before you begin you need to add the GitHub extension to Visual Studio. Here is how you do it:

    • This tutorial covers how you can take an existing project in Visual Studio, and add it to a local Git repository, and then upload it to a remote repository like GitHub.
    • You need to have an existing GitHub account.
    • The benefit of adding it to a remote repository is that you now have an off-site backup in case you lose the local copy. You also can then clone it on a different machine and work on the project from multiple locations.

    • This tutorial covers how you update your local repository with changes you have made to your project, and then how to push these changes to your remote repository on GitHub so that you can retrieve those changes from another computer.
    • You need to have have created a local Git repository which is covered in the Adding an Existing Solution to Git tutorial.

    • This tutorial covers how you can retrieve a repository from your GitHub account on a new computer to continue working on it, and how you can update your local project from your GitHub account if you have been working on it from another location.
    • You must have a GitHub account with at least one repository on it.

    • This tutorial covers how you can clone someone else's public repository onto your own local machine, and then add it to your own GitHub repository so you can have your own version.

    • This tutorial covers how you can return your project to an earlier state if needed.
    • You would want to do this if you somehow broke your project, or made significant changes that you decided need to be undone.


Team Explorer

All of your Git options are found in the Team Explorer. If you do not see the Team Explorer tab next to the Solution Explorer, select the View menu, and then click on Team Explorer.

Troubleshooting

1 - Close Visual Studio and open it again, this can solve some errors.

2 - Worst Case Scenario, remove/delete your local repository (don't do this unless you have a fairly up-to-date version in your remote repository on Guthub), and Clone it again from your remote repository (GitHub).

Error Pushing updates to GitHub.

If you get a DB.Lock error when you try to commit a change, see this link for a possible solution:

https://stackoverflow.com/questions/47460039/vs-2017-git-local-commit-db-lock-error-on-every-commit/47472811