Getting Git ??? Part: 1 ( Repository, Commit, Cloning, Branch, Push…)

ATUL JAIN
9 min readJan 18, 2021
GitHub Lesson Poster

A Basic Guide to Repository, Local installation, Connect local with Github, Branching, Cloning, Commit, Push.

The first commit message for the Git project was ‘initial version of “git”, the information manager from hell’ — Linus, 4/7/05

The learning curve for Git is pretty steep compared to many other systems. After looking at many developers who love Git after they finally understand it, but getting to that point is often somewhat painstaking.

This article is aimed at the developers/students who have heard good things about Git but don’t know where to start or why it’s so wonderful. It is meant to explain Git as simply as possible in a clean, concise, easily readable volume.

Let’s have a recap of what all we are going to cover in this:

Photo by Cathryn Lavery on Unsplash
  1. Understanding What is Git?
  2. Downloading and Installing Git in the local system.
  3. Creating a new account in Github.
  4. Creating a new repository, and Cloning it to the local setup.
  5. Adding new changes, committing, pushing new changes to Github.
  6. Branching and Version control.

Understanding Git or GitHub?

Let’s dive into, but before I need to clear one thing:

Git is not GitHub, both are different and I’ll explain that later in this article.

The image representing GitHub animation

You must have come into a situation when you created folders like “test1”, “project”, “project_updated”, “project_update_final”. It’s basically because you are working on something and then something new came to your mind, but you also wanted to keep the current version. What if I say now there is no need to create folders, again and again, someone else will do it for you.

That’s great right, Git is the solution technology that is doing it for you. All you have to do is commit every step and then you can navigate to each commit if something goes wrong in the future. As simple as that 😎.

flow of git commits date wise.
Git commit Flow

This is how Git preserves your work history. Flow direction is bottom to top, at the top comes latest commit.

Example of single git commit details
Git Single commit

On each commit you will find information as:

  1. On the top, you will see the date of the commit.
  2. Below that message to describe the commit along with the username who did the commit.
  3. On the right side, Verified, means changes have been approved.
  4. After that 📋, this is the clip. Used to copy commit key(SHA key). Next to that, you will find the initials of the commit key.
  5. Next “ ‹› ”, this to jump at a particular version of the application.

Setup: Create a GitHub account and install Git in the local system.

Starting with the GitHub Account

  1. Go to link https://github.com/
  2. Click on Sign up, then fill in the details and verify your account with email.

3. After login, this is how your account will look.

4. Next, let’s create our first repository on Github. Click on “Create repository” on the left side.

Fill in the details and click on “Create repository”:

Next, this is how our page will look. This is the first GitHub repository you created. Congratulations 😎

Ok for now let’s keep our repository like this, while we install git in our local system.

Installing Git in the system (We are doing windows setup):

  1. Go to link https://git-scm.com/downloads

2. Download the setup and install.

3. Once installed let check whether it installed correctly or not. Try to search git on the start menu, if something like this appears…

wolaaa!!!

You succeed. ✔

Git Bash

Now it’s time to understand the difference between Git and GitHub we have seen both now.

Git is a free and open-source version control system, originally created by Linus Torvalds in 2005. Git is distributed: every developer has the full history of their code repository locally.

On the other hand

GitHub is a code hosting platform for collaboration and version control. It lets you (and others) work together on projects.

👉 A GitHub repository can be used to store a development project.

👉It can contain folders and any type of files (HTML, CSS, JavaScript, Documents, Data, Images).

So basically, if I take an example assume a (🎂)recipe as project/repository and (📔)recipe book as GitHub basically collection of projects and repositories. Now there are some (📏)rules which must be followed while writing a recipe like image should be included, ingredients should be mentioned in bullet form, and many other.

Connect your local Git to GitHub by Cloning.

Now, this basically means whatever changes you are going to do to your laptop at home can be synced with your project on GitHub. So in the future, if anything happens to your laptop, your project is still safe and you can access it anytime on GitHub.

Sweet Right 🎈😊

👉 First, we will clone the GitHub repository.

Go to GitHub, and navigate to the earlier created repository as below

GitHub Repository

Cloning: You can clone an existing Git repository from elsewhere. So, you end up with a Git repository on your local machine, ready for work.

👉 After that select dropdown on the Code button next to the Add File button.

Make sure HTTPS is selected if you haven’t set up an SSH key, now that’s another topic that can’t be covered here.

Now below next to the URL click on 📋 the clip icon, by this, you are copying the address of your GitHub repository.

👉 We are done on GitHub, now move to GitBash, just search in the start menu and open it. A terminal window will appear.

Git Bash

First, navigate to the location where you need to store your project.

You can see here how to navigate in git bash Click Here

After that Type the following command

git clone <URL you just copy>.

Git clone command

If it shows any ERROR, try adding an SSH key. Here is the process to add an SSH key to your GitHub Account. (Click Here)

Git Cloning

If cloning was successful, your terminal will show the message as above.

👉 Now open the folder where you cloned the repository. Here you will find a “README” file.

Add another file as “new.txt” and put your name into it.

File Explorer

Save it and close it. ✔

👉 Open Git Bash and navigate to the folder where the repository was cloned.

type command “git add .” this is to collect all the changes made.

after that type the command “git status”, this will show you current changes.

Git Status command

After that we have to commit changes along with the commit message, think it as you have packed the changes in a box with a message on it, ready to be sent.

type git commit -m “new file added”

Git commit command

Ok, the last step is to send the package to GitHub. For that, we will use the git push command.

Git push structure

type git push origin main

here remote = origin, which represent link to your GitHub repo.

and main is your default branch when you create repository. We will understand branching in details in next section of this blog.

Git Push command

Once pushed, you will see a success message as above.

👉 Go on and check your GitHub whether new changes updated or not.

If Yes. Congratulations 😍 you git your first git commit and push successfully.

GitHub Repository

As you can see above it worked, and changes are reflected on GitHub.

Last but not least Branching in Git, very important 👀

Git branch is a way to create a new branch from the existing project without affecting the current project. This way you can continue to work on your own branch and the original project remain in the same state.

For example, consider a tree with many branches. What if you break one branch from it, will other branches also drop from the tree? No right because they have the same initiation point but beyond that point, they are entirely independent.

Branch policies are an important part of the Git workflow and enable you to:

  • Isolate work in progress from the completed work in your main branch
  • Guarantee changes build before they get to the main
  • Limit who can contribute to specific branches
  • and many more…

Let me walk you through with a simple example:

✔ Open your GitHub repository “newRepo”

Git Repository. Branch menu

✔ Open dropdown where main is written 🔽.

Git Select branch from branch menu

✔ A panel will appear with a search panel inside. If a branch already created you can search them and select them. Else GitHub will create a new branch with the name you enter in the search box. And then press ENTER.

GitHub new branch created

✔ Beautifully done, you have successfully created a new branch.

Let's get into some details regarding Git, you will better understand as now we have done a practice related to that.

This workflow consists of five types of branches, each with different roles:

👉 Master now called the main branch, Git automatically creates the main branch when we first create a repository. Code in the main branch considered production-ready.

👉 Feature/Topic branch, When you start working on a new feature/bug fix, you should create a feature/topic branch. A feature/topic branch is normally created off a develop branch.

👉 Release branch, When you roll out a new release, you create a release branch. A release branch helps you to ensure that the new features are running correctly.

By convention, release branch names normally start with the prefix “release-”.

👉 Hotfix branch, When you need to add an important fix to your production codebase quickly, you can create a Hotfix branch off the master branch.

By convention, hotfix branch names normally start with the prefix “hotfix-”.

👉 Develop/Integration branch, A develop/integration branch should be kept stable at all times. This is important because new branches are created off of this branch. It is called a develop branch because all new features are first tested on the develop branch and after that develop branch is merged to the main branch.

SUMMARY

First I would like to thank you for reading this article. Give me a clap and share this, it helps in a motivational boost. 😍

In this article

🐱‍🏍 We learned Git fundamentals.

😃 Created a new GitHub account with the email.

💾 Created a new repository.

💻 Installed Git in the local system.

🎞 Cloning GitHub branch to the local system.

🧨 Making new changes locally and pushing them to GitHub.

🌴 Creating a new branch from the main branch and understanding Git branching fundamentals.

--

--