<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Arindam Lahiri</title>
    <description>The latest articles on DEV Community by Arindam Lahiri (@arindamlahiri).</description>
    <link>https://dev.to/arindamlahiri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F494340%2Fc20439f8-58cc-4a94-916c-41ffd9ef5dcb.jpg</url>
      <title>DEV Community: Arindam Lahiri</title>
      <link>https://dev.to/arindamlahiri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arindamlahiri"/>
    <language>en</language>
    <item>
      <title>Using Git inside VS Code</title>
      <dc:creator>Arindam Lahiri</dc:creator>
      <pubDate>Mon, 19 Oct 2020 20:00:00 +0000</pubDate>
      <link>https://dev.to/arindamlahiri/use-git-inside-vs-code-14f</link>
      <guid>https://dev.to/arindamlahiri/use-git-inside-vs-code-14f</guid>
      <description>&lt;p&gt;In this tutorial I will show you how you can use &lt;strong&gt;&lt;em&gt;git&lt;/em&gt;&lt;/strong&gt; inside &lt;strong&gt;&lt;em&gt;VS Code&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you are someone who is already comfortable with using git the &lt;em&gt;traditional&lt;/em&gt; way from the terminal/git bash, stick around and you might find some tricks to save a lot of time in your workflow.&lt;/p&gt;

&lt;p&gt;And if you are someone who does not like the terminal a lot and would just prefer a GUI flow, then &lt;strong&gt;this is definitely for you&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://code.visualstudio.com/download" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; and &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;Git&lt;/a&gt; installed on your system.&lt;/li&gt;
&lt;li&gt;Basic knowledge of &lt;strong&gt;git&lt;/strong&gt; and &lt;strong&gt;github&lt;/strong&gt;. (I would recommend this &lt;a href="https://youtu.be/SWYqp7iY_Tc" rel="noopener noreferrer"&gt;crash course&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Open up your project folder in VS Code.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: If you have done any step(like initialising the git repo) from outside of VS Code, you can just skip to the next step as VS Code keeps a track of your entire git history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Additional Note&lt;/strong&gt;: If you are like me and prefer keyboard shortcuts over clicking around with your mouse, do check out &lt;em&gt;&lt;strong&gt;Step 6&lt;/strong&gt;&lt;/em&gt; 👀&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 1: Initialise a git repo&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Look for the Source Control icon in your sidebar and click on it.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnjx720mk8wjx2avn91dj.png" title="Source Control" alt="Source Control Icon"&gt;
&lt;/li&gt;
&lt;li&gt;You should see some text that says something like &lt;em&gt;this folder does not have a git repo&lt;/em&gt;. Click on the button that says "Initialise repository"&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 2: Add files to staging area&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Now you would see all your files listed down under a section titled &lt;em&gt;&lt;strong&gt;Changes&lt;/strong&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;When you hover over any file, you would see three options. Click the third one which is a plus(+) icon. This would add that particular file to the staging area.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fw4l8lkz54zel29eln13o.png" title="File" alt="File"&gt;
&lt;/li&gt;
&lt;li&gt;To add all the files to the staging area, (similar to the command &lt;code&gt;git add .&lt;/code&gt;) hover over the &lt;em&gt;&lt;strong&gt;Changes&lt;/strong&gt;&lt;/em&gt; title and click on the plus(+) icon there.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ea7n227itjwk8q9ggjx.png" title="Changes" alt="Changes"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 3: Commit the changes&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Your staged files would be now be in the appropriately named &lt;em&gt;&lt;strong&gt;Staged Changes&lt;/strong&gt;&lt;/em&gt; section&lt;/li&gt;
&lt;li&gt;To commit your changes look for a ✔ in the Source Control pane
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faw302zw6o75qmc6xsxn5.png" title="Source Control Pane" alt="Source Control Pane"&gt;
&lt;/li&gt;
&lt;li&gt;A prompt will ask you for a commit message, enter a relevant message and hit enter. Your changes are now committed.&lt;/li&gt;
&lt;li&gt;If you only work in local repositories, then this is it. Head over to Step 6 for some time saving tricks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 4: Add a remote&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Head over to Github, create a new repository and get the url (ending with '&lt;em&gt;yourusername/repositoryname.git&lt;/em&gt;') that you would otherwise use in the &lt;code&gt;git remote add&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;Now back in VS Code click the three dots for more options in the &lt;em&gt;&lt;strong&gt;Source Control Pane&lt;/strong&gt;&lt;/em&gt; (see image in &lt;em&gt;Step 3&lt;/em&gt;) and then select &lt;strong&gt;Remote&lt;/strong&gt;&amp;gt;&lt;strong&gt;Add Remote&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Enter the url that you got earlier and after that enter a name for the remote repo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Step 5: Push your code to Github&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;For your first push, open the options in the &lt;em&gt;&lt;strong&gt;Source Control Pane&lt;/strong&gt;&lt;/em&gt; and select &lt;strong&gt;Branch&lt;/strong&gt;&amp;gt;&lt;strong&gt;Publish Branch...&lt;/strong&gt;. You might be asked to login to github, do that.&lt;/li&gt;
&lt;li&gt;In a few seconds, your code will be available in your Github repository.&lt;/li&gt;
&lt;li&gt;For subsequent pushes, going to &lt;strong&gt;Options&lt;/strong&gt;&amp;gt;&lt;strong&gt;Push&lt;/strong&gt; will push your code to Github.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;[Optional] Step 6: Add keyboard shortcuts&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;One under-rated feature of VS Code is the ability to add a keyboard shortcut for almost anything inside the editor. Personally I have used it to ease my workflow with git/github.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open the command palette with &lt;code&gt;Ctrl+Shift+P&lt;/code&gt;, search for 'Open keyboard shortcuts' and open it.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fomzrvu8q0lrah1mj7mqu.png" title="Keyboard Shortcuts" alt="Keyboard Shortcuts"&gt;
&lt;/li&gt;
&lt;li&gt;Now search for 'git' in the search bar and you can choose any action and assign it to any unused key combination.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxa85zdv9fprqzej6mj28.png" title="Search" alt="Search"&gt;
&lt;/li&gt;
&lt;li&gt;For example, I have added the following combinations for staging all files, committing all files and pushing the changes.
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffvvhapvcc1otr2icu3bb.png" title="My Shortcuts" alt="My Shortcuts"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are a lot of git features baked into VS Code, these were basic actions to get you started. I hope you found this tutorial helpful. If you run into any issues, drop a comment down below or contact me on &lt;a href="https://twitter.com/arindamcodes" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;. &lt;br&gt;
Also feel free to share any of your productivity tips. Would love to see what you all are using.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Update(14/01/2021) - If you need a visual guide for this, do checkout this video. &lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4dSA-NVP3e0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

</description>
      <category>git</category>
      <category>vscode</category>
      <category>productivity</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
