Skip to content

Öykü Yılmaz Git Research

oykuyilmaz1 edited this page Feb 16, 2020 · 1 revision

Research: Git as a version management system

Have you ever heard about Git or GitHub? Do you ever wonder how Git stores all the versions of you work? Or have you ever lost time just because you made a mistake somewhere in your project and cannot find your old version of code? No worries, you can find the answers you need in this research.

Jump to:

  • What is a Version Control System?
  • What is Git
  • Basic Commands
  • Basic Terminology
  • What do these commands do behind the curtains?

What’s a version control system?

A version control system tracks the history of changes as people and teams collaborate on projects together. Everyone can find out an old version of the project. They also can answer these questions about a change: Who made it, when was it made, the comments of the developers when these changes were made.

What is Git and why do we use it?

From the definition of the official website of 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."

Git lets developers see the entire timeline of their changes, decisions, and progression of any project in one place. Also, it is easy for developers to communicate through Git.

Basic Commands

git init - initializes a repository

git clone - copies a repository from a remote source

git status - gives you the status of your files in your repository

git add - adds changes and creates a staging area

git commit - commits your changes, creates an object and gives them an ID.

git branch branch_name - creates a branch

git checkout branch_name - makes your desired branch active

git push - adds your local changes to the remote

git pull - takes the updates from your remote

git merge - combines two branches

What do these commands do behind the curtains?

When you type git init, it creates a repository. That resembles the root if a tree:

1

When you git add files, it creates a staging area like:

2

When you git commit, you see that it gives this commit an id(it is A in the figure but normally it is a long hash, you can check Basic Terminology). Also your default branch(master in the figure) and head branch comes with you along your journey:

3

Then suppose you made a change and added this change. It creates another staging area on the top of your first commit:

4

And when you git commit, the head and master branches come with you to your last commit. Also your commit has another id(in the figure it is B):

5

Now, if you want to make changes but you do not want to mess with your original files, you create a branch. Let's call it feature. The code for that is git branch branchname. If you want to continiue with your new branch you need to git checkout branchname. Or you can type(in this case of course) git checkout -b feature to do both of the tasks in the same line:

6

So that you have a new branch, you can git add your changed files:

7

When you git commit, this time your selected branch(which is green) goes with this commit and your inactive branch(master, blue) stays where you leave it:

8

Now suppose you made some changes and added them and committed them three times:

git add files

git commit

git add files

git commit

git add files

git commit Then your tree should look like this:

9

Now comes the good part, suppose you want to go back to the point where you left the master branch. All you need to do is git checkout master. your master branch becomes active(green) and your feature branch becomes inactive. Remember, head follows you no matter which branch is selected:

10

You can git add files and git commit and your tree becomes:

11

And if you think that all changes are okay and you no longer need to seperate them, you can git merge and ta-daa, all your changes merge to one last commit:

12









Clone this wiki locally