How to install Git and use GitHub in VSC

What is Git?

By far, the most widely used modern Version Control System (VCS) in the world today is Git. Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

The major difference between Git and any other VCS is the way Git thinks about its data. With Git, every time you commit or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots.

For more detailed information, check the following link.

What is GitHub?

GitHub is a provider of Internet hosting for software development and version control using Git. It offers the distributed version control and source code management functionality of Git, plus its own features. It provides access control, and several collaboration features such as bug tracking, feature requests, task management, continuous integration and wikis for every project.

GitHub offers its basic services free of charge. Free GitHub accounts are commonly used to host open-source projects. It basically allows you to share your code with your work partners, friends, and the rest of the world. There are a lot of libraries already in GitHub, that you can check and adapt to your own usage.

Why should you use them?

Git will help you to share and work with more people on your projects. GitHub will store your repositories and make them public, so more people can review your codes and ask for commits if they made a small improvement on them. This will help you to avoid the necessity of sending codes to your colleagues every 10 minutes.

If you have multiple teams working on different projects but in the same repository, you can create multiple branches and work on them at the same time, and when you finally want to merge them, Git will provide you some tools to fix the errors in the process.

Most of the big companies use it because it is really efficient for the management of big projects and teams. Learning how to use it, even in your own projects, will make your profile to look more professional and well prepared to jump into a new team.

So go their web page and create your account.

Download and installation Git (Windows)

Go to the official Git web page and download the installator and follow all the steps. There are just a few that you need to change some settings. The other ones, you can leave them as default.

Git installator.
Git components.
Default editor for Git.
Setting the environment variable.

Download and installation GitHub Desktop(Windows)

GitHub Desktop is a tool that will help you with a more friendly interface to control the repositories. Go to the official web page and download the installator, and then follow its steps.

GitHub Desktop installator.
Sign in to GitHub.
Manage the repositories in your computer.
Inside of a repository.

Git in Terminal

The following commands will help you to check that you installed Git properly, and set it with your profile.

$ git --version
$ git config --global user.name "[name]"
$ git config --global user.email "[email address]"
Git in the terminal.

Git commands

This part summarizes commonly used Git commands line instructions for quick reference.

CONFIGURE TOOLING

Configure user information for all local repositories.

$ git config --global user.name "[name]"
Sets the name you want attached to your commit transactions
$ git config --global user.email "[email address]"
Sets the email you want attached to your commit transactions
$ git config --global color.ui auto
Enables helpful colorization of command line output

CREATE REPOSITORIES

Start a new repository or obtain one from an existing URL.

$ git init [project-name]
Creates a new local repository with the specified name
$ git clone [url]
Downloads a project and its entire version history

MAKE CHANGES

Review edits and craft a commit transaction.

$ git status
List all new or modified files to be committed
$ git diff
Shows file differences not yet stagged
$ git add [file]
Snapshots the file in preparation for versioning
$ git diff --staged
Shows file differences between staging and the last file version
$ git reset [file]
Unstages the file, but preserve its contents
$ git commit -m "[descriptive message]"
Records file snapshots permanently in version history

GROUP CHANGES

Name a series of commits and combine completed efforts.

$ git branch
Lists all local branches in the current repository
$ git branch [branch-name]
Creates a new branch
$ git checkout [branch-name]
Switches to the specified branch and updates the working directory
$ git merge [branch]
Combines the specified branch's history into the current branch
$ git branch -d [branch-name]
Deletes the specified branch

REFACTOR FILENAMES

Relocate amd remove versioned files.

$ git rm [file]
Deletes the file from the working directory and stages the deletion
$ git rm --cached [file]
Removes the file from version control but preserves the file locally
$ git mv [file-original] [file-renamed]
Changes the file name and prepares it for commit

SUPRESS TRACKING

Exclude temporary files and paths.

*.log
build/
temp-*
A text file named .gitignore suppresses accidental versioning of files and paths matching the specified patterns
$ git ls-files --other --ignored --exclude-standard
List all ignored files in this project

SAVE FRAGMENTS

Shelve and restore incomplates changes.

$ git stash
Temporarily stores all modified tracked files
$ git stash pop
Restores the most recently stashed files
$ git stash list
List all stashed changeset
$ git stash drop
Discards the most recently stashed changeset

REVIEW HISTORY

Browse and inspect the evolution of project files.

$ git log
Lists version history for the current branch
$ git log --follow [file]
Lists version history for a file, incluiding renames
$ git diff [first-branch]...[second-branch]
Shows content differences between two branches
$ git show [commit]
Outputs metadata and content changes of the specified commit

REDO COMMITS

Erase mistakes and craft replacements history.

$ git reset [commit]
Updoes all commits after [commit], preserving changes locally
$ git reset --hard [commit]
Discards all history and changes back to the spicified commit

SYNCRONIZE CHANGES

Register a repository bookmark and exchange version history.

$ git fetch [bookmark]
Downloads all history from the repository bookmark
$ git merge [bookmark]/[branch]
Combines bookmark's branch into current local branch
$ git push [alias] [branch]
Uploads all local branch commits to GitHub
$ git pull
Downloads bookmark history and incorporates changes

Git in VSC

You can use the VSC terminal to use Git commands, but it will help you to have some extensions to improve the interaction.

Extensions

Extension Description
GitLens — Git supercharged GitLens supercharges the Git capabilities built into Visual Studio Code. It helps you to visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more.
GitHub Pull Requests and Issues This extension allows you to review and manage GitHub pull requests and issues in Visual Studio Code.

Most used commands

If you are already in the folder of the cloned repository, these are the commands I used the most:

$ git add *
It adds all the new files and removes the ones you suppressed
$ git commit -a -m "a short message summarizing the changes"
This will commit the changes you did to the files and give the short message as a reference to explain what you did
$ git push
This will update your changes to your repository.
$ git pull
Sometimes you will work on the same project with someone else, or make some changes to the files on another computer and you want to pull the changes to your computer.