VS Studio Code has advanced Git features as well, such as managing remote repositories, merging conflicts, and you can even configure VS Code as your external Git editor. ![]() So far, we have looked at how to use basic Git operations in Visual Studio Code to track our work. You don't have to do anything else, just type the command Git inside the Command Palette, and you get a dropdown list of the available commands you can quickly choose from. You can access Git commands from the Command Palette ( F1 on Windows and Linux, Ctrl/Cmd+Shift+P on Mac) as well. Use Git Commands from the Command Palette ¶ Or use the Command palette ( Ctrl/Cmd+Shift+P) and select Git: Checkout to. To switch between branches, click the name of your current branch in the bottom left and select your new branch from the list shown. We also have a helper command adx git:branch that makes it easier to follow our suggested naming convention. Or you can open the Command palette by hitting Ctrl+Shift+P (Cmd+Shift+P on Mac), then typing the Git: Create Branch command into the input bar. In Visual Studio Code, you can create new branches by clicking on the name of the current branch in the bottom left and selecting + Create New Branch. We recommend using short-lived feature branches and merge requests to facilitate code reviews and tracking changes in systems like CMC. This is useful for experimenting with new solutions as well as to facilitate code reviews using merge requests. Git allows you to easily create and switch between branches. VS Code uses 3 kinds of gutter indicators: Speaking of reviewing changes, it's also important to notice Visual Studio Code's gutter indicators that annotate changes compared to your previous commit, even when the side-by-side view is not open. In the Git View, you can just double click on the file you want to compare, and VS Code will show the current and previous versions side by side, so you can quickly compare them. Review Changes ¶Īs you proceed with your work, if you are not sure about how the current version compares to your last commit, you can quickly check the differences. In the screenshot below you can see how your code editor looks right after committing. If you make new changes in your workspace, the new changes will appear again in the SideBar, and you'll need to commit them again once you have made significant changes that you want to record. Your Git working directory is clean, all the changes you made so far are tracked, and your Git View says there are 0 changes (it always compares the current state to your last commit). ![]() Now you have made your first commit, and the initial state of your repository is recorded. Type your commit message into the input bar at the top of the SideBar, and click on the little tick icon. Since in this example this will be the initial commit, let's use the not-so-creative "Initial Commit" message. In order to commit the staged changes, you need to add a commit message that describes the changes you made since your previous commit. Staged changes are not yet recorded, you also need to commit them, so that later you can have a look at or move back to the current state of your repository. If you want to stage all your files at once, click the + button that appears when you hover over the Changes subtitle. To stage a file, click the + button that appears when you hover over that file in the Changes section.Īfter you click on the files you want to stage, Visual Studio Code moves that file from the Changes folder to the Staged Changes folder, that means that now they are in the staging area. Before committing, you need to add the files you want to track with Git to the staging area, or in other words you need to stage the changes. git folder inside your workspace (you can't see this from VS Code, as it's a hidden directory, but you can find it in your file manager in the root folder of your project), and it will also add your untracked files to the Side Bar.Īfter your Git repository is set up, it's time to create your initial commit ( a commit is a recorded state of your whole repository you can later move back to). To do so, click on the Initialize Git Repository button in the Git View. If your workspace isn't yet tracked by Git, first you need to initialize a new repository. The Side Bar contains a separate Git View you can quickly open by clicking on the Git icon in the View Bar. ![]() Visual Studio Code supports Git by default, which means you don't have to install any packages or extensions to use it. Git allows you to track your work, move back and forth between versions, and work on different branches at the same time. Integrated Git support is one of the great features of Visual Studio Code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |