Skip to content

Git Research

Orhun Görkem edited this page Mar 28, 2021 · 7 revisions

What is Git?

Git is a version control system (VCS). VCS is a helpful software to utilize the colloboration of software developers and accumulate the history of their work.
There are two types of VCS:

  • Decentrilized VCS (DVCS)
  • Centrilized VCS (CVCS)

Git is a DVCS, which is advantagous in case of failure of servers. In CVCS, risk of losing whole work and data exists because it is dependant to a central server. In DVCS, clients fully mirror the whole repository, that's why if the server goes down, any client can restore the repository. In addition, clients can use the repository offline in DCVS.

Advantages of Git

  • Git is free and open source.
  • Git is fast with two reasons: Being a DVCS, gives the option to make most of the operations offline, independent of a central server. Additionally, core part of Git is implemented with C which overcomes the runtime overheads.
  • Git is very secure. It uses SHA1 hash function to identify objects in database. Every file and commit is check-summed and retrieved by its checksum at the time of checkout.
  • Git has efficient branch management system.

Terminology

Local repository: The private workspace where users can perform many operations such as add file, remove file, rename file, move file, commit changes, and many more.

Blobs: Blob stands for Binary Large Object. Each version of a file is represented by blob. A blob holds the file data but doesn’t contain any metadata about the file.

Trees: Trees represent directories. They keep blobs as well as other sub-directories. A tree is a binary file that stores references to blobs and trees.

Commit: Commit is a node-like object that holds the current state of the repository. Commits are named with SHA1 hashes and keeps a pointer to the parent commit object.

Branches: Branches are used to create another line of development. Usually, a branch is created to work on a new feature. Once the feature is completed, it is merged back with the master branch and deleted. Every branch is referenced by head, which points to the latest commit in the branch.

Tags: Tags are very similar to branches, but the difference is that tags are immutable. They are usually used for product releases.

Clone: Clone is an operation that creates the local instance of the repository.

Pull: Pull is an operation that copies the changes from a remote repository instance to a local one.

Push: Push is an operation that copies changes from a local repository instance to a remote one.

Git vs Github

While Git is the Version Control System that helps us to keep and manage our source code history, GitHub is the cloud-based hosting service that helps us to manage our Git repositories. One can use git repositories with other hosting services such as GitLab or BitBucket.

Git Commands

git init <repositoryname> creates a new blank repository. It is used to make the current directory a git repository. A subdirectory .git is created that contains metadata of the repository.

git add <filename> writes file to the local repository. git add . adds all the files.

git commit -m <commit message> creates an object with a unique id. Id contains information of content, date, author and previous commit. Commit is used to save the changes to repository.

git status lists all the untracked files. You can see which files are modified.

git diff displays the difference between what is on the disk and what is in the repository. It is used to view the conflicts.

git reset undo changes that are added but not committed yet. It can move HEAD to a specified state.

git branch <branchname> creates a new branch. It facilitates to make changes without affecting other branches.

git checkout <branchname> switches to branch which commits are will be done to. git checkout -b [branch name] creates a new branch and switches to it.

git merge <branchname> writes a new commit that merges content of the specified and the master branch.

git clone <repository url> makes o copy of a git repository. The remote repository URL is referred to the origin.

git push stores data from your local to git repository.

git pull stores data from git to local repository.

References

Clone this wiki locally