Using Git on Windows

Here are step by step on how to using Git on Windows

Using Git On Window Part 1

Git is a distributed source version control software designed by the original inventor of Linux namely Linus Torvald. It is designed to help different software developers work on the same project so that they can track who is doing what and track all the updates and changes made to the project but it can also be used to track changes in any finding of files.  In this series, we give a brief introduction on installing git on a windows computer, and a brief look at how git is designed to work.

Download Git for Windows

Please Download git from here (Windows)

Git basically lets you control the changes made to a file by many people. Anyone can push their changes to git and let everyone see those changes. Others can pull down the changes and work on them.  It is important to understand this push and pull that goes on.

Git Usage Architecture

The barebone basics of Git is to serve as a tool for synchronizing files in a workspace with the files in a repository on Github.  The workspace is on the local computer or on your PC and the said repository is on the internet on Github.  You will need to create the depicted repository once you have created a GitHub account.  Go online to www.github.com and create the account (requires user name and password)

The workspace is just a directory on the computer. For example, once you create a repository called ‘pythonportfolio’ on GitHub  ( which is easy to do once you go to github.com, then create your GitHub account and then create the repository as depicted below)

Using Git On Window Part 1

Create the Repository

 

In the above, a user account dace89 has created a repository called ‘pythonportfolio’ – which is the repository where all these users python development work will be stored.

Now to the windows command line where the repository is REPLICATED on the local machine.

In windows at the ‘run ‘ command utility type ‘cmd’ to open the command prompt. Or, Press Windows+R to open the “Run” box. Type “cmd” into the box. This will open the run command prompt. Since you already installed git for windows you can go ahead and type ‘git’.

 

The result of typing ‘git’ basically shows you how to use the ‘git’ command with all its options as in the above figure.

 

Create the matching workspace from the repository

The next command is to clone the repository on GitHub ‘pythonportfolio’ on to the local machine with

‘git clone https://github.com/Dace89/pythonportfolio.git

The above will copy the remote repository onto the local directory in My Documents. That means a directory called ‘pythonportfolio’ will be created in My Documents by this ‘git clone’ command.

git commit

Now we will go through other commands such as ‘git add’ and ‘git commit’ commands to update the workspace and the remote repository.

Here you will learn how to create files in the workspace and synch then with the repository automatically.

Using Git On Window Part 2

We will create this piece of python code in the workspace ‘pythonportfolio’.

The code is saved in the directory that was previously created in part 1 – ‘pythonportfolio’. The saved file is ‘sum_avg.py’. As you can see it runs perfectly by skipping the print of ‘banana’ from the list.

Pycharm

Before we begin, let’s create another python file with pycharm. The file forloop2.py is created and as soon as it is created it is added to the workspace with a ‘git add’ command. This is because pycharm comes integrated with Git.  In the figure below, you can see that pycharm will ask you to use ‘git add’ to add this file to the workspace or to the ‘pythonportfolio’ folder.

git status

If you go to the windows command prompt and run ‘git status’ command to add the file to the git workspace  ‘pythonportfolio’ for the first time.

git adds

After ‘git adds’, the file is ready to be committed to the workspace.

If we create another file forloop3.py in ‘pythonportfolio’  – forloop3.py  we can do that with notepad as depicted below.

forloop3.py

Then we execute ‘git status’ command to see what the status of the working space repository is different for forloop3.py which is in the ‘untracked files’ – which means fit does not consider it part of the local workspace.

After we execute

‘git add forloop3.py’ followed by ‘git status’  we can see that the untracked file forlopp3.py has been added to the files that are ready to be committed to the git workspace on the local machine.

 

As shown above, the file forloop3.py has now become a file that has changes to be committed.

Now let’s see what is on GitHub.

git push

We can see that only the first file is there after the’ git push’ command was executed. Now if we execute git push again, we will see that the new files added to the local directory on the computer will get pushed on GitHub.

 

Next, we go and check on GitHub to see what was pushed there.

We can see that for loop files have not been updated to GitHub. This is because they were not committed. You need to commit changes and then push those changes to GitHub so that other developers will have access to them.

 

If we check on Github we will see that the change was updated and the updates pushed to GitHub.

 

With a series of ‘git add’, ‘git commit’ and ‘git status’, and ‘git push’ commands we were able to show you the basic functionality of Git.  Bookmark our site and come back to read more about our software series.

 

 

Add a Comment

Your email address will not be published. Required fields are marked *