Hermann  Frami

Hermann Frami

1626064500

Essential Git Commands Every Programmer Should Know

Learn the basics of Git

Before we jump into Git, let’s talk about version control briefly. Version control or source control systems give us the power to collaborate, manage and track code history over time. The system stores metadata inside a data structure called a repository, which allows us to use features like revert to undo code. Thus, it makes software development easier and faster. There are two types of version control systems, centralized and distributed. So, Git is a distributed version control system. It is one of the most used source control systems created by Linus Torvalds in 2005. From this post, you’ll learn some commonly used Git commands.

Setup

For this setup, I’ll be using the  Git command-line tool. Also, there are multiple  Git GUI clients available for different operating systems. I’ll be using  GitHub for the repository hosting service, which comes with tons of cool  features.

Git repositories

There are two ways to start a Git repository, local and remote.

Local repository

We can turn a local directory into a Git repository using the Git command git init. The Git workflow for the local repo would be creating a local repo and finally pushing it to a remote repository to collaborate with others.

[start] the working directory  → git add → staging area → git commit → local repository → git push → remote repository [end]

Now, we can pull any changes from the remote repo to update our local repository using the Git command git pull.

[end] the working directory ← git pull ← remote repository [start]

Git commands

First, let’s create a local repository.

cd Desktop
git init neptune
cd neptune
touch README.md
echo TODO > README.md
git add README.md
git commit -m "README"
git push

#git #github #programming #technology

Essential Git Commands Every Programmer Should Know