Starting with this posting, we will upload a series of articles that can help with Python development. The series will be written in four articles, and the contents are as follows, and if necessary, additional posts will be uploaded as a separate series.

In this article, we will show you what Git is and Why do we need it. Also, we will give a brief intro to how we can start and use Git.

  1. Git Basic
  2. Virtual Environment
  3. PEP8
  4. Jupyter

What 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 [1]. It provides us a history of content changes and facilitates collaborative changes to files [2].

Figure 1. Examples of Using Git [3].


Why Do We Need Git

When we work on a project and do something creative and productive, we repeat the following four steps [2].

  1. Create things.
  2. Save things.
  3. Edit things.
  4. Save the things again.

By repeating the above steps, we add new things, delete unnecessary ones, request modifications, and make corrections where necessary. To make this process straightforward and efficient, we turn to the help of version control. Through the version control system, we can easily track the followings [2].

  • When we did it.
  • Why we did it.
  • What the contents of the change.

This makes it possible to efficiently understand the project’s process and be more productive when revisiting the project in the future.

For these reasons, we cannot overemphasize the necessity of version control when working on projects through collaboration as well as personal projects. By using Git, we can take these benefits of version control.

Figure 2. Workflow with Git [4].


Basic Git Commands

The following are essential terminal commands for Git. It may be difficult to memorize, but it is good to understand only its purpose. As long as you understand each command’s purpose, you can easily use Git through a GUI, which will be covered in the following section.

For reference, the contents are referred to as the following links.


git init

$ git init [project-name]
  • This command is used to start a new repository.


git clone

$ git clone [url]
  • This command is used to obtain a repository from an existing URL.


git add

$ git add [file-name]
  • This command adds a file to the staging area.


git rm

$ git rm [file-name]
  • This command deletes the file from your working directory and stages the deletion.


git commit

$ git commit -m “Message to go with the commit here”
  • This command records or snapshots the file permanently in the version history.


git status

$ git status
  • This command lists all the files that have to be committed.


git push

$ git push [variable name] master
  • This command sends the committed changes of master branch to your remote repository.
$ git push [variable name] [branch-name]
  • This command sends the branch commits to your remote repository.


git branch

$ git branch
  • This command lists all the local branches in the current repository.
$ git branch [branch-name]
  • This command creates a new branch.
$ git branch -d [branch-name]
  • This command deletes the feature branch.


git checkout

$ git checkout [branch-name]
  • This command is used to switch from one branch to another.
$ git checkout -b [branch-name]
  • This command creates a new branch and also switches to it.


git pull

$ git pull [repository link]
  • This command fetches and merges changes on the remote server to your working directory.


git merge

$ git merge [branch-name]
  • This command merges the specified branch’s history into the current branch.


git diff

$ git diff
  • This command shows the file differences which are not yet staged.
$ git diff [first branch-name] [second branch-name]
  • This command shows the differences between the two branches mentioned.


git stash

$ git stash save
  • This command temporarily stores all the modified tracked files.
$ git stash pop
  • This command restores the most recently stashed files.
$ git stash list
  • This command lists all stashed changesets.
$ git stash drop
  • This command discards the most recently stashed changeset.


GitKraken

There is an entry barrier to use the commands described above in a terminal window. For those who have difficulty using Git in a terminal window, we suggest to use a GUI called GitKraken. With GitKraken, you can intuitively and easily manage projects without memorizing all the git commands. Figure 3. is a screenshot of GitKraken.

We can do the basic operation as the git commands described above through the buttons in Area 1. In Area 2, GitKraken shows the files that have been modified compared to the log, whether these files are added in the staging area, and allows us to commit. Lastly, in Area 3, it shows us the workflow of the project.

Figure 3. GitKraken Screenshot.


One More Thing 😜

Those who want to use Git only with commands in a terminal window, not using a GUI, or who want to have a deeper understanding, can learn without losing interest through the quest-game-type tutorial provided at the following link.

Figure 4. Git Command Line Tutorial Screenshot.


Reference

[1] Git. [Online]. Available: https://git-scm.com/. [Accessed: 01-Oct-2020].

[2] “Git Basics Episode 1,” Git. [Online]. Available: https://git-scm.com/video/what-is-version-control. [Accessed: 01-Oct-2020].

[3] S. C. Atuonwu, “5 Git Commands You Should Know, with Code Examples,” freeCodeCamp.org, 10-Jun-2020. [Online]. Available: https://www.freecodecamp.org/news/5-git-commands-you-should-know-with-code-examples/. [Accessed: 01-Oct-2020].

[4] Atlassian, “Gitflow Workflow: Atlassian Git Tutorial,” Atlassian. [Online]. Available: https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow. [Accessed: 01-Oct-2020].