Image from Double Momentum

“Always have a backup plan.” — Mila Kunis

What is Version Control

The version control system is a special type of software that can keep track of every modification done to the codebase, this allows the team to manage the source code without collisions and identify what are the changes done through the time to the system. SVN, CVS, Git are popular version control systems.

Why Git So Special?

Git is distributed - Git does not need a central server to work even in the local machine software can maintain using Git.

It supports parallel development - Using the concepts of branching and merging git provides the ability to maintain more than one active development cycle parallelly, without affecting each other.

Other than that it’s simplicity and speed compared to others.

Before getting started with Git follow the link to download and install git.

Concepts of Git

Initializing a Git repo

1. Navigate to the folder 
cd myRepository
2. initialize as a git repository
git init

Branches of Git

How Git Branching Works

To view available branches

git branch

To create branch

//Create a branch
git branch -b <branchname>
//Create a new branch and Navigate to it
git checkout -b <branch_name>

It is important here that when creating the branch it uses the current branch you are in to derive from. it is better to view the current branch or first navigate to it using.

git checkout <branch_name>

Here are the other commands related to branches

// Safe delete a branch
git branch -d <branch_name>
// Force delete a branch
git branch -D <branch_name>

Commits of Git

And when the developer made a change to the codebase, he/she has to decide whether this change is working and keep it for delete back to the previous state. If the dev decides to keep it, it should be “committed” to the repository. and making it in the current state.

How Git Keep Tracks of its commits (Image from Git. SCM)

to commit a change to the repository, first, it should be added to the repo

git add --all (adding all the changes)
git add changedFileOnly.c (add only one file)

commit changes

git commit -m "meaningful commit message"

and the commit will now be recorded.


Multiple developers working on a different set of features but at the end of the day, those are all relevant to the same application, in that the changes are merged into the main/master branch.

How Merging works
//Navigae to the main branch
git checkout main
git merge branch01 //Merge branch 01 to main
git merge branch02 //Merge branch 02 to main

If there are modifications for the same file, same lines of code, git cannot identify which one to keep or remove at that time merge conflicts should be removed by the developer.

Other features of Git

git stash //put to the shelves
git pop // get back from the shelves
git stash apply //apply the working changes to the working copy

git diff - If the developer not sure where are what are the changes made in two arbitrary commits by diff command it will display the changes been made.

git diff //Overall changes done in the directory

.gitignore -o this is actually a file in the git directory, where we can ignore the files and folders when doing the commits, a file or folder defined in this file will not add to the commits.

Git != Github && Git != GitLab

The power of Git we talked about “Git is distributed”, Unlike decade before the development teams are now spread in every continent at that time managing a local copy and keep updating is time-consuming services like GitHub provided solution for this by using cloud technologies and providing global accessible. and automating the processes like testing and deployment.

There are a few commands and methods used in these services.

git clone - Clone is used to get the copy of the existing repository in a service like GitHub or GitLab to our local machine.

git clone <repo> <directory>git clone ssh:// clone clone -branch new_feature git://remoterepository.git

git push - Git push is used to push our changes into the remote repository.

git push <remote> <branch>//Force push
git push <remote> --force
//push to the main branch
git push origin main

git fork - In git fork rather than the original server repository, the user can have its own complete repository, The repositories are independent of one another but can merge to the original repo or from the original repository to forked repository.

For more detailed information please use the references below.

Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store