Using Git with Visual Studio Code

Credit:

https://github.com/firstcontributions/first-contributions/blob/master/github-windows-vs-code-tutorial.md

  1. Find – Find a repository on Github (can be found on https://github.com/explore)
  2. Fork – Fork this repository by clicking on the fork button on the top right of this page. This will create of copy of this repository in your GitHub account. GitHub keeps track of the relationship between your repository and the one you have forked it from. You can think of your repo as a working copy. 
    Note for Beginners: Most top-level GitHub repositories (i.e. ones not forked from any other repository) have a small core team of people who can directly commit changes. All other contributors must fork the repository and make changes in the fork, then create a “Pull Request” to ask for their changes to be merged back into the top-level repository . If the top-level repository administrator likes the changes they will be merged and you will gain instant fame and fortune!
  3. Clone – The next step is to clone your repository down to your machine so you can begin making changes. VS Code needs the URL of your repository , so click the “clone” button and then click the “copy to clipboard” icon.

    Now open up Visual Studio Code. The welcome page of VS Code will pop up. From there press F1 to open up the bar shown below. Notice that there is already a > (greater than) sign in the text field. Now type in git cloneand press Enter
    Paste the URL of your repository (This will be in the form https://github.com/YOURUSERNAME/REPOSITORY) and press Enter. This will open up a File Explorer where you can then choose where the Git repository should be stored.
    Note: Make sure it is the forked repository and not the original one, otherwise it won’t work.
    You should see a status popup on the bottom right of Visual Studio Code. After it has finished, you can open up the cloned repository (now a folder on your machine) using the buttons in the dialog.
  4. Branch – Open up the command palette again by pressing F1. Type in branch and select the create branch command from there. In the next step type in the name of your new branch. Press enter and the branch will be created. The branch is also already checked out.
  5. Name – Open Contributors.md and add your name anywhere in the file. This file contains GFM (GitHub Flavored Markdown) which is a proprietary flavor of the markdown syntax. Copy one of the other contributors’ lines and modify it with your name to make sure you get the syntax right – it can be picky.
  6. Commit and Push – On the left side of VS Code is a menu with 5 icons displayed. Select the version control/Source Control icon. (Shortcut : Ctrl + Shift + G)

    The file explorer displays all files which were changed after the last commit. By hovering the files and clicking the + (plus) the files are staged. Type something in the line on top of the explorer and press the check mark. The changes are now committed to your local copy. Now the changes have to be pushed back to GitHub.
    Use the three-dot icon to open up the menu where you select the Publish Branch option. This should open up a dialog to put your GitHub credentials in.
  7. Submit – At this point you have completed your change but it still only resides in your repository . This step will show you how to submit a request to the administrator of the top-level repository to merge your change. In your repo on GitHub you’ll see the Compare & pull request button next to the new branch notification. Click on that button.

    Now submit the pull request.