Importance of Git in SDE

Don Namgyal
4 min readMay 20, 2020

Git Whaaaat?

Git is a distributed version control system widely used in the software development world to allow teams to collaborate seamlessly. Git has set the benchmark for others to follow when it comes to source code management (SCM). It is not to be confused with GitHub, which is a cloud-based hosting service built around Git to serve as the central source code repository. Git is a command-line tool that runs locally on your computer to manage your source code without a need for a network connection. Together, they power many of the applications we use today. Three of the most useful features Git excels in is branching, staging area, and having multiple workflows.

Multiple Workflows

As a distributed source code management tool, anytime a user runs the git clone repo_name command, Git clones the repository in their machine which also contains every change ever made to the source code. Thus, if the main source code were to crash or get corrupted, any user with the repository in their machine could push their code up to the server using git push and get back to running without any major delays.

Staging Area

The staging area is as the name says, it is where you put your code when you are ready to commit it to the repository. To add modified files to be committed, you need to explicitly tell Git to do so, or else it won’t know to include them in the commit. This can be done in one of two ways, git add file_name or git add . command. The first command tells Git to track a specific file, whereas the second command tells Git to track all files in the current directory. The changes in the files could be as little as a single space or a period, or 100 lines of codes, Git will track them once told. Once those commands are run, you can check to see the files that are tracked and staged to be committed by running git status. When you are ready to commit, a simple git commit -m “commit message” will create your commit. You can create multiple commits to keep track of what was changed each time before you push your code to the main repository.

Branching & Merging

The branching model is a feature that brings out the mad scientist inside every single developer. It gives you the freedom to experiment and try new things without worrying about possibly destroying the company. You can create a new branch with the command: git branch new_branch. This forks the master at that instance and creates a new working directory called new_branch which contains a copy of the master branch. To begin with the crazy experiments, you need to switch to the newly created branch, which can be done with git checkout new_branch command.

Once in the new branch, you start writing your code and test it out. If the feature works as expected and is ready to be combined with the master branch, it is time to merge. Merge is Git’s way of combining the different branches into one. You have the receiving branch and a merging branch, and you want to ensure that you are in the correct receiving branch. The git status command should tell you the branch you are in. If not in the correct branch, use the git checkout branch_name to switch to the branch you want. That is followed by git merge merging_branch_name.

Depending on your teams workflow style, occasionally you may encounter merging conflicts that prevent you from successfully merging. It usually occurs when two or more people have made changes to the same file. In that case, Git will ask you to fix the conflicts before you commit the changes. You are given three options before you can successfully merge: keep your branch’s changes, keep only the other branch’s changes or accept both, and create a new change. Depending on your selection, you would then add the changes to the staging area with git add . command, followed by git commit -m “message”.

Once the branch has successfully merged, you can go ahead and delete the branch with git branch -d branch_name command. If your branch has not merged, you will receive an error message. If you do not care for the branch, git branch -D branch_name command will force delete it.

These are the basics concepts of Git. If you understand what I have written, then you are more than capable of starting to track your project code using Git. Cheers!!!

--

--