DEV Community

Cover image for Git for Beginners
saber-mekki
saber-mekki

Posted on

Git for Beginners

Birth of Git

Until April 2005 Linus Torvalds was using BitKeeper for version control of the Linux Kernel development. He had a large number of volunteer developers working on the Linux Kernel and their contributions had to be managed. BitKeeper was a nice tool for managing the enormous contribution by the developers. The Linux developers used the tool for free after an agreement between the two parties as BitKeeper was a proprietary source control management system which means you had to pay for the use of the tool. There came a conflict of interest after Andrew Tridgell created an open-source client for accessing the Bitkeeper version control system by reverse-engineering the BitKeeper protocols. This caused the copyright holder to withdrawal the free-to-use policy that they had earlier agreed upon. Many developers of the Linux kernel gave up access to the BitKeeper.

Linux knew he had to act fast to replace the version control system that he knew and loved so he took a working vacation to decide on what to do as the current free-to-use version control systems could not solve his problems at the time. The result of his vacation was the birth of a new version control system named Git.

Strengths of git

  • Works in multi-platform.
  • Small and quick.
  • Distributed development.
  • Strong support for non-linear development.
  • Automatic Garbage Collection.

Why Use It?

Git is useful to anyone who writes code or track changes to files, it is the most commonly used version control system.
Git lets multiple developers easily work together on the same project with speed and efficiency.Tracking and history are available, even when off-line.
Git is used for tracking and managing changes in files (In reality, git doesn't save the file but save the history of changes in a file).

Image description

Installation

On Linux

  • Using apt:

sudo apt-get update
sudo apt-get install git-all

  • Using dnf:

sudo dnf install git-all

How use it

After creating the project we will start by :

git init
Enter fullscreen mode Exit fullscreen mode

Create an empty Git repository or reinitialize an existing one, in this stage you will be in "default" branch called "master",it is a naming convention for a branch.

git status 
Enter fullscreen mode Exit fullscreen mode

Used to display the state of the repository and staging area(display the change in your project)

Tow floors appear to us after use this command:

Untracked: This file exists locally, but isn’t a part of the Git repository. The file’s change history will not be recorded and it will not be pushed to remote.

Tracked: Git tracks the file’s change history and it will be pushed to remote copies when running git push. At this point, the are two situations:

"Unstaged changes":
Exist in your working directory, but Git hasn’t recorded them into its version history yet.

"Staged changes":
Are a lot like unstaged changes, except that they’ve been marked to be committed the next time you run git commit.

git add
Enter fullscreen mode Exit fullscreen mode

Add file contents to the index. The status of your changes goes from "Untracked and Unstaged" to "Staged".

git commit
Enter fullscreen mode Exit fullscreen mode

Record changes to the repository. before committing you must know the "Conventional Commits", it mean you will try to add a human and machine readable meaning to commit messages see:Conventional Commits

git push 
Enter fullscreen mode Exit fullscreen mode

To integrate the branch to the remote repository.

git log --oneline --decorate --all --graph
Enter fullscreen mode Exit fullscreen mode

Show commit logs.

Git Extensions must have in VS Code

  • GitLens

  • Git Graph

  • Git History

Hope you were able to gain something from this article.
If you have any questions do not hesitate to contact me saber mekki

Top comments (0)