avatarEugenia Anello

Summary

The web content provides a comprehensive guide on how to update a GitHub repository using Visual Studio Code, detailing the steps for cloning, committing and pushing changes, and making pull requests.

Abstract

The article "How To Update Your GitHub Repository in Visual Studio Code" offers a step-by-step tutorial for developers looking to streamline their workflow when managing repositories on GitHub. It begins by outlining the prerequisites, including the installation of Visual Studio Code, Python, Git, and essential VS Code extensions. The author then explains the process of cloning a GitHub repository to a local machine, committing changes to files, and pushing those updates back to the remote repository. Additionally, the article covers the importance of setting up Git configurations and making pull requests to synchronize changes when collaborating with others. The guide emphasizes the efficiency gains and time-saving benefits of using Visual Studio Code for GitHub repository management.

Opinions

  • The author advocates for the use of Visual Studio Code due to its efficiency and support for multiple languages, as well as its extensibility through additional functionalities via extensions.
  • Cloning a GitHub repository locally is presented as a superior method to manual file insertion, particularly for repetitive tasks and collaborative work.
  • The author expresses that using Visual Studio Code for Git operations like committing and pushing changes, as well as making pull requests, is a significant improvement over traditional methods.
  • The article suggests that the integration of GitHub within Visual Studio Code can lead to better version control practices and more streamlined collaboration among team members.
  • The author implies that mastering these tools can free up time for developers to focus on other important tasks, indirectly endorsing Visual Studio Code as a valuable tool for productivity enhancement.

How To Update Your GitHub Repository in Visual Studio Code

An overview to clone a repository, push changes, and make pull requests in VS code

Photo by ick Morrison on Unsplash

For a lot of time, I updated my GitHub repository by simply inserting the files. But doing this can waste a lot of time when you have to repeat the same operation more than one time and when you are working with other people in that repository.

Recently, I have started to use Visual Studio Code when working on Jupyter notebooks and editing file .py. It’s a really efficient IDE that supports multiple languages and allows you to provide additional functionalities by installing extensions.

In this post, I am going to show how to work and update your GitHub repository on Visual Studio Code. The steps are as follows:

  1. Prerequisites
  2. Clone GitHub Repository
  3. Commit and Push Changes
  4. Make a Pull Request

1. Prerequisites

Illustration by author

Before getting started with GitHub on Visual Studio Code, there are previous requirements you need to know. First, you need to install Visual Studio Code, Python (at least Python 3.6), and Git. Once they are installed, you can enter in Visual Studio Code and select the Python interpreter from the Command Palette, which will appear with the keyboard shortcut Ctrl+Shift+P.

Illustration by author

After this, we need to install the following extensions within VS Code:

  • Python Extension
  • GitLens Extension
  • GitHub Pull Requests and Issues

Let’s also check on Visual Studio Code to see if Git is enabled in the settings:

Illustration by author

The last and most important step is to click on the Account button located at the bottom left of the VS Code’s Panel and sign in with GitHub:

Illustration by author

If all these steps are satisfied, we can finally start this tutorial!

2. Clone GitHub Repository

The first operation is to clone your GitHub repository on your local computer using Visual Studio Code. In this way, you have a full copy of the repository on your local PC and you can easily add, remove, and update the files on GitHub using Visual Studio Code directly.

To clone a GitHub repository, you need to have a GitHub repository already. If you don’t have any repositories on GitHub, I suggest you create a new repository and upload Python files that will be updated later.

There are three different ways to clone your GitHub repository:

  • From the terminal git clone <repository.git>
  • Using the Git:Clonecommand in the Command Palette
  • Using the Clone Repository button in the Source Control tab, located in the left-side panel

In this post, I am going to show you how to clone the repository using the Source Control tab. First, you click Clone Repository and, then, a GitHub repository dropdown of your account will appear (if you have already signed in with GitHub, as I showed in the prerequisites section). Here’s what it looks like:

Illustration by author

Select one of your repositories, and then select the repository location, which must be a folder. Once you choose the folder, you click the Select Repository Locationbutton.

Illustration by author

Now you should see the local repository opened on Visual Studio Code, as shown below:

Illustration by author

After this, we need to set the Git username and email address with the git config command on the terminal. Then, let’s open the terminal and write the commands. You only have to substitute “Your Name” and “[email protected]” with your GitHub username and email.

git config --global user.email "Your Name"
git config --global user.name "[email protected]"

Et Voilà! Now we finally have a copy of the GitHub Repository on the local computer, and we are done with most of the configurations!

3. Commit and Push Changes

Illustration by author

The biggest advantage of having a local copy of your GitHub repository is the possibility to easily update your files. For example, let’s add a simple comment in the Jupyter notebook, and let’s save the file. In this way, you can visualize the changes of your local GitHub repository on the Source Control icon.

There are three steps to add your local modification on GitHub Repository:

  1. Click the + icon by the modified file.

2. Once the file is added, press the v button, and write a message. For example, I wrote “comment added” and pressed Enter.

3. Select the Push option after selecting the ... icon.

Three steps to make push changes. Illustration by author

If we check the changed file on the GitHub repository, you’ll see the modification, which is shown below:

Modification on the official GitHub repository. Illustration by author

Great! We updated the Jupyter notebook using only Visual Studio Code!

4. Make a Pull Request

Illustration by author

A pull request is useful to have the most updated version of your GitHub repository. If you work in the repository with other collaborators that often update the files, these changes can’t be seen on your local copy on VS Code without doing a pull request.

Don’t worry, a pull request is very fast to do. You only need to select the Pull option after selecting the ... icon.

Final Thoughts

I hope you found this tutorial useful to get started with Git and GitHub on Visual Studio. When I discovered it, I never stopped using it because it helps me avoid wasting time. With more time, I can focus on other things.

Thanks for reading! Have a nice day!

Other related articles

Useful References

Did you like my article? Become a member and get unlimited access to new data science posts every day! It’s an indirect way of supporting me without any extra cost to you. If you are already a member, subscribe to get emails whenever I publish new data science and python guides!

Programming
Python
Github
Software Development
Vs Code
Recommended from ReadMedium