Learn how to install and use git on Windows

Shamli Singh
5 min readAug 27, 2017

--

So I am starting my career as a software developer with a reputed firm, and projects here require that the programs be tracked using version control. That being said, git is the most popular version control system around, and is mostly used along with github.

Now, I have been using git since my college days on Ubuntu. However, when I started working at my firm, I needed to switch to using git on Windows. Finding a proper tutorial for git on Windows was really a tough job, and though youtube videos were of some help, I happened to be stuck after some point. Hence, I decided that it was time to write a blog post that shows how to install git on Windows, hassle free!

Ready to download!

  1. Go to git’s official website: https://git-scm.com/
  2. It automatically checks your platform and suggests you to download for Windows. Click on that link. You will be redirected to a page, where download starts automatically.

Have your own github account!

  1. While git downloads, how about make your own github account! Go to github and create a new account.
  2. Choose a unique username for your account, with a strong password.

Create a new project

  1. Click on start a project.
  2. Give a name to your project, let’s say Workspace.
  3. You can have a description for your new project.
  4. You can also edit privacy settings for the project.
  5. Once all fields are covered, check the box saying Initialize this repository with a README. README file is a file which gives other developers a gist of what the project contains. README can also act as a mini-documentation or a user manual for your project.
  6. Then click on Create repository.

Once git download finishes…

Assuming the download was successful, click on the downloaded .exe file (v2.14.1 is the latest while I write this post).

An installation wizard opens up talking about GNU General Public License. Click on next.

Leave the default settings for Select Components. This contains both Git Bash and Git GUI checked.

For Adjusting your PATH environment, choose Use Git from the Windows Command Prompt.

For Choosing HTTPS transport backend, choose Use the native Windows Secure Channel Library. This is especially helpful if you are a new student or developer and may not know how SSH works. Let’s stay out of the complexity of OpenSSL for git.

For Configuring the line ending conversions, choose Checkout Windows-style, commit Unix-style line endings, as we don not want to mess up the internal configurations of how git works on Windows.

For Configuring the terminal emulator to use with Git Bash, choose Use MinTTY.

Keep Configuring extra options untouched, and click on install.

Get started!

Once git is installed, choose the option to go to Git Bash. You don’t really need to view release notes, unless you are really keen to do it.

Git Bash looks like a normal command prompt. By default, it is in home directory (~)

You can work in home directory, but I’ll suggest creating a new directory in home or D:/ or whichever you want.

$ cd D: Administrator@MyWindows MINGW64 /d $ mkdir git Administrator@MyWindows MINGW64 /d $ cd git/

It is time to set your username and email in bash. This will point to your github account.

Administrator@MyWindows MINGW64 /d/git $ mkdir git Administrator@MyWindows MINGW64 /d/git $ git config --global user.name "yourusername" Administrator@MyWindows MINGW64 /d/git $ git config --global user.email "youremail@domain.com"

Replace yourusername and youremail@domain.com with your own credentials.

Get your existing repository on your local machine

So our repository currently exists on a remote machine i.e. github server. So it’s time to get it on your own machine so that you can start working on your project.

Administrator@MyWindows MINGW64 /d/git $ git clone "https://github.com/yourusername/Workspace.git" Cloning into 'Workspace'... remote: Counting objects: 5, done. remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 5 Unpacking objects: 100% (5/5), done.

Move to your repository directory

Administrator@MyWindows MINGW64 /d/git $ cd Workspace/

Time to add a new file to your project repository

Create a new file in your project, let’s say fibonacci.cpp. After you are done, this file needs to be added to git. Follow the below commands:

Administrator@MyWindows MINGW64 /d/git/Workspace (master) $ git add fibonacci.cpp Administrator@MyWindows MINGW64 /d/git/Workspace (master) $ git status On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: fibonacci.cpp

Once the file is staged on git, it needs to be committed. Committing a file ensures that your file with any new changes will not be lost in case of a system crash. Commit as per following command. Also, don’t forget to add a commit message for your commit (this is for other developers and your future reference).

Administrator@MyWindows MINGW64 /d/git/Workspace (master) $ git commit -m "Print Fibonacci series upto given limit" fibonacci.cpp [master 57f87a5] Print Fibonacci series upto given limit 1 file changed, 45 insertions(+) create mode 100644 fibonacci.cpp Administrator@MyWindows MINGW64 /d/git/Workspace (master) $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean

Pushing to remote git…

Once you start working with git, it is a good practice to keep pushing your changes in the project to git’s remote machine. This ensures that your project files do not get corrupted on your machine if it malfunctions.

To push to github, do the following. This action will prompt you for your credentials. Enter them so that your machine connects to remote repository.

Administrator@MyWindows MINGW64 /d/git/Workspace (master) $ git push -u origin master Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 878 bytes | 439.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/yourusername/Workspace.git db65d35..57f87a5 master -> master Branch master set up to track remote branch master from origin.

Note that currently you are pushing to your master branch. Concepts of forking and merging will be discussed in some other post in future.

That’s it!

You are done with your first project using git. You can now easily commit and push your projects to github, as well as download some exciting open-source projects from github.

Practice a little more and you will be an expert git user.

Note: With minor URL changes, this tutorial should work for other git service providers like gitlab and bitbucket. You are free to use any other service. However, the basic working remains same.

--

--

Shamli Singh

MS Computer Science student at San Jose State University, Newbie at blogging, Fascinated with amazing tech! GHC 2020