banner



How To Register Source Control In Visual Studio Code

Habitation / Version Decision-making with Git in Visual Studio Code and GitHub

Overview

Git is a distributed version command system. Git repositories can live locally (such as on a programmer'due south motorcar). Each developer has a copy of the source repository on their dev auto. Developers can commit each gear up of changes on their dev auto and perform version command operations such as history and compare without a network connection.

In this lab, yous will larn how to clone an existing Git repository from GitHub. In addition, you lot volition learn about Git branching and merging support. You will utilize Visual Studio Lawmaking, just the same processes employ for using any Git-compatible client with GitHub.

Prerequisites

  • Visual Studio Code with the C# extension installed.

  • Git for Windows 2.21.0 or later.

Exercise one: Configuring the lab environment

Job one: Configuring Visual Studio Lawmaking

  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, y'all tin skip to the next task.

  2. From the master menu, select **Final New Final** to open up a final window.
  3. Execute the control below to configure a credential helper.

                                      git config --global credential.helper wincred                              
  4. The commands below will configure your user name and electronic mail for Git commits. Supersede the parameters with your preferred user name and electronic mail and execute them.

                                      git config --global user.name "John Doe"  git config --global user.email johndoe@case.com                              

    Task 2: Forking an existing repository

  5. In a browser tab, navigate to the GitHub project at https://github.com/Microsoft/PartsUnlimitedE2E.

  6. Click Fork. This will re-create the entire repository into the account yous specify so that you can work on it without impacting the original repo.

  7. Select the GitHub business relationship to fork into. The fork should consummate quickly.

Task 3: Cloning an existing repository

  1. Your GitHub browser tab should now be open up 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 downwardly the latest source to work with. From the Clone or download dropdown, click the Copy to clipboard button.

  3. Open an instance of Visual Studio Code.

  4. Printing Ctrl+Shift+P to prove the Control Palette. The Control Palette provides an easy and convenient way to access a wide variety of tasks, including those provided past third party extensions.

  5. Execute the Git: Clone control. Information technology may aid to type "Git" to bring it to the shortlist.

  6. Paste in the URL to your repo and press Enter.

  7. Select a local path to clone the repo to.

  8. When prompted, log in to your GitHub account.

  9. Once the cloning has completed, click Open. You can ignore any warnings raised well-nigh opening the projects. The solution may not be in a buildable state, but that'south okay since nosotros're going to focus on working with Git and edifice the projection itself is not necessary.

Exercise 2: Saving work with commits

When you make changes to your files, Git will record the changes in the local repository. You can select the changes that you lot want to commit by staging the changes. Commits are always made against your local Git repository, so you don't have to worry about the commit being perfect or ready to share with others. You lot can make more commits every bit you lot continue to work, and push button the changes to others when they are set up to be shared.

What's in a commit?

Git commits consists of the following:

  • 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(due south). Git manages your code history using these references.

  • A message describing a commit. Y'all give this bulletin to Git when you create the commit. It's a good idea to go along this message descriptive, merely to the point.

Task 1: Committing changes

  1. From the Explorer tab, open /PartsUnlimited-aspnet45/src/PartsUnlimitedWebsite/Models/CartItem.cs.

  2. Add a comment to the file. It doesn't really matter what the annotate is since the goal is just to make a change. Press Ctrl+South to save the file.

  3. Select the Source Command tab to see the i alter to the solution.

  4. Enter a commit bulletin of "My commit" and press Ctrl+Enter to commit it locally.

  5. If asked whether you would like to automatically stage your changes and commit them directly, click Always. We will hash out staging later in the lab.

  6. Click the Synchronize Changes push button to synchronize your changes with the server. Confirm the sync if prompted.

  7. If prompted, log in to your GitHub account.

Chore 2: Staging changes

Staging changes allows you to selectively add together certain files to a commit while passing over the changes fabricated in other files.

  1. Return to Visual Studio Code.

  2. Update the open up CartItem.cs form by editing the comment you made earlier and saving the file.

  3. Open Category.cs likewise.

  4. Add a new comment to Category.cs and so there volition be two files with changes. Save the file.

  5. From the Source Command tab, click the Phase Changes button for CartItem.cs.

  6. This will prepare CartItem.cs for committing without Category.cs.

  7. Enter a comment of "Added comments". From the More Actions dropdown, select Commit Staged.

  8. Click the Synchronize Changes push button to synchronize the committed changes with the server. Note that since only the staged changes were committed, the other changes are notwithstanding pending locally.

Exercise 3: Reviewing history

Git uses the parent reference information stored in each commit to manage a full history of your development. You lot can hands review this commit history to find out when file changes were made and decide differences between versions of your code using the concluding or from one of the many Visual Studio Code extensions available. You can also review changes using the GitHub portal.

Git'south utilize of the Branches and Merges feature works through pull requests, so the commit history of your development doesn't necessarily grade a directly, chronological line. When you use history to compare versions, retrieve in terms of file changes between two commits instead of file changes between 2 points in fourth dimension. A recent modify to a file in the master branch may accept come from a commit created 2 weeks ago in a feature branch but was just merged yesterday.

Job 1: Comparing files

  1. In the Source Control tab, select Category.cs.

  2. A comparison view is opened to enable yous to easily locate the changes you've made. In this case, it's just the one annotate.

  3. Render to the GitHub browser tab.

Task 3: Reviewing commits

  1. Switch to the GitHub browser tab. Yous tin can review the latest commits on GitHub under the Commits tab.

  2. The recent commits should exist right at the pinnacle. Click the most contempo 1.

  3. This view enables you to review the changes applied by this commit. Click View file.

  4. Click History to runway the commits made to this file over fourth dimension.

  5. Click the Browse repository at this indicate in the history button for the second commit. This was the start commit pushed from this lab.

  6. You can now review the state of the repo at the fourth dimension this commit was pushed. The dropdown at the acme provides a user-friendly way to switch betwixt branches as well.

Exercise four: Working with branches

Yous can manage the piece of work in your GitHub repo from the Branches tab. You can besides customize the view to track the branches you care most nigh and so you can stay on top of changes made by your team.

Committing changes to a branch will not affect other branches, and y'all can share branches with others without having to merge the changes into the master projection. You tin besides 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, only rather uses the history information stored in commits to recreate the files on a branch when you start working on it. Your Git workflow should create and use branches for managing features and bugfixes. The residuum of the Git workflow, such every bit sharing code and reviewing code with pull requests, all work through branches. Isolating work in branches makes it very unproblematic to change what you are working on past simply changing your current co-operative.

Task one: Creating a new co-operative in your local repository

  1. Return to Visual Studio Code.

  2. Click the master co-operative from the bottom left.

  3. Select Create new branch.

  4. Enter the name "dev" for the new co-operative and press Enter.

  5. If prompted, select principal as the reference branch.

  6. You are now working on that co-operative.

Task two: Working with branches

Git keeps rails of which branch you are working on and makes sure that when yous checkout a co-operative your files match the most recent commit on the branch. Branches let you lot work with multiple versions of the source lawmaking in the aforementioned local Git repository at the aforementioned time. Y'all can employ Visual Studio Code to publish, check out, and delete branches.

  1. Click the Publish changes button adjacent to the branch.

  2. From the GitHub browser tab, select the Branches tab.

  3. Y'all should encounter the newly pushed dev co-operative. Click the Delete this branch push button to delete it.

  4. Return to Visual Studio Code.

  5. Click the dev branch.

  6. Notation that in that location are two dev branches listed. The local (dev) branch is there because it'due south 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 bank check it out.

  7. Printing Ctrl+Shift+P to open the Command Palette.

  8. Beginning typing "Git: Delete" and select Git: Delete Co-operative when it becomes visible.

  9. There is only one local branch to delete, so select it.

  10. Click the chief branch.

  11. Note that the local dev co-operative is gone, but the remote origin/dev is still showing.

  12. Press Ctrl+Shift+P to open the Command Palette.

  13. Offset typing "Git: Fetch" and select Git: Fetch (Prune) when it becomes visible. This control will update the origin branches in the local snapshot and delete those that are no longer there.

  14. You can bank check in on exactly what these tasks are doing by selecting the Output window at the bottom of the screen. If this window isn't visible, yous can restore it with the **View Output** carte.

  15. Notation that if you don't come across the Git logs in the output console, you may need to select Git equally the source.

  16. Click the chief branch.

  17. The origin/dev branch should no longer be in the listing.

Exercise 5: Managing branches from GitHub

In addition to all the functionality available in Visual Studio Code, you can also manage your repo branches from the GitHub portal.

Task i: Creating a new co-operative

  1. Switch to the GitHub browser tab.

  2. Return to the Code tab root.

  3. From the branches dropdown, enter a co-operative proper noun of "release". Click Create co-operative: release. This will create a new branch and switch to it.

  4. You tin can confirm that the newly created release branch is selected.

  5. Return to Visual Studio Code.

  6. Press Ctrl+Shift+P to open the Control Palette.

  7. Start typing "Git: Fetch" and select Git: Fetch when it becomes visible. This command will update the origin branches in the local snapshot.

  8. Click the master branch.

  9. Select origin/release. This volition create a new local branch called "release" and check it out.

Task 2: Deleting a co-operative

  1. Return to the GitHub browser tab and navigate to the Branches tab.

  2. Click the Delete push button for the release co-operative.

  3. All the same, perchance we should keep it effectually for a fiddling longer. Click Restore to disengage the delete.

Chore three: Tagging a release

  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 information technology as such, return to the Code tab and select Releases.

  2. Click Create a new release.

  3. Enter tag and release names of "v1.one" and a Description of "Swell release!". Click Publish release.

  4. You lot have at present 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 past name.

Exercise vi: Managing repositories

You can create Git repos in team projects to manage your project's source code. Each Git repo has its own set of permissions and branches to isolate itself from other piece of work in your project.

Task 1: Creating a new repo

  1. From the New dropdown, select New repository.

  2. Set the Repository name to "New Repo". Annotation that yous also have the option to create a file named README.md. This would be the default markdown file that is rendered when someone navigates to the repo root in a browser. Additionally, you tin preconfigure the repo with a .gitignore file. This file specifies which files, based on naming pattern and/or path, to ignore from source control. There are multiple templates bachelor that include the common patterns and paths to ignore based on the projection type you are creating. Click Create repository.

  3. That's information technology. Your repo is ready. Y'all now have the ability to clone information technology with Visual Studio or your tools of pick.

Task 2: Renaming and deleting Git repos

  1. Sometimes you'll have a need to rename or delete a repo, which is just as piece of cake. Navigate to Settings.

  2. You can update the name of the repository here.

  3. From the Danger Zone section of the settings view, click Delete this repository.

  4. Enter the full repo proper noun and click the choice to delete the repository.

Source: https://www.azuredevopslabs.com/labs/azuredevops/github/

Posted by: kleinpereadesen.blogspot.com

0 Response to "How To Register Source Control In Visual Studio Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel