Loading...

What is Git: Features, GitHub, Commands and more (2022)

What is Git: Features, GitHub, Commands and more (2022)

Introduction

I’ll try to explain what Git and GitHub are throughout this blog. Git is a version-control system, and GitHub is a site that provides version control for Git. Git is commonly referred to as a programmer’s best friend. I’ll try to make it as simple as possible for you to understand.

What is Git?

Git is a free and open-source distributed version control system, a type of SCM that stands for software configuration system/ source code management.

Pretty complicated things I said there, right? Don’t worry if you didn’t understand it right away I’ll try to put it in such a way that it would much is easier for you to understand.

Suppose, while working on a project you did some changes on the project you felt at the time were necessary but after a while, you feel like the older version of your project was better.

You would like a way where you could just go back in time and get the older version of your project back, right?

This is what version control in Git does. Git is used to store the changes /history logs of all and everything you modified in your source code.

When working in a team or an open source project, multiple people contribute to the source code a very sacred and important thing to the project. Git is used to store every modification made to the code by multiple people to avoid any errors made by humans to the source code.

Now you know what a version control system is but what is distributed version control system?
previously all SCMs used only one copy of the source code i.e. on the main server which is quite risky. You might lose everything if anything happens to the server.

When using a distributed version control system like Git, you can have multiple copies of your repository on the server as opposed to just one.
You have two copies—one with you as a local repository and one on the server as a remote repository.

Pardon me if I didn’t already explain what a repository is because you’re going to hear that word a lot while working on Git. A repository is a folder that contains every project file and the history of all the modifications done to the project file.

Now you know what Git is but I have a question for you :
When so many people are working on the same project how do you manage to merge all those modifications to the main source code?
To understand this question you first need to understand GitHub and one of its features: Branching.

Installing Git on your device is very easy. Follow the following steps:

  • Go to the Git website, select OS and version and download the setup.
  • install the setup.
  • After installation open Git bash on your device and set your global email and username.

To set a username type this command in Git Bash

git config --global user.name "NAME"
Code language: Tcl (tcl)

To set email type this command in Git Bash

git config -global user.email"[email]"
Code language: Tcl (tcl)

What is GitHub?

GitHub is a web hosting service that provides distributed version control for Git.
I mean you need a portal from where you can work on a project with multiple people, right?
That’s what GitHub provides us.
Git helps us with version control whereas GitHub is a portal where you can work with multiple people on an open-source project or private company project.

Go through this quick guide on how to get started with GitHub.

Branching

Getting back to the question I proposed earlier how do you merge multiple code modifications by multiple users into the source code?
So there is a concept called branching that sites like GitHub provide us. While working on a remote project with a group there is a guy who overlooks everything.
First, you use the git fetch command to import a remote repository commit to your local repository. The main source code is on the remote repository and lies in the main branch previously known as the master branch. When you fetch a repository and modify the code, your modified code lies in an extra side branch. when you feel like the code is good enough to be added to the source code you use the git push command to upload your local repository to the remote repository. please know that your code is still not merged with the main source code in the main branch it still resides in the extra branch. Now the guy overlooking everything looks at your contributed code checks if it’s good enough and decides whether it should be added to the main branch or not.

Source: https://learngitbranching.js.org/?NODEMO

GitHub Features

GitHub isn’t the only web hosting service that helps us with Git there are many others like Gitlab, Bitbucket, etc. but there are features that GitHub provides us that make it superior to its competitors.

Features like:

  • Codespaces
  • GitHub Copilot
  • Pull requests
  • Discussions
  • Code search & code view
  • Notifications
  • Code review
  • Code review assignments
  • Code owners
  • Draft pull requests
  • Protected branches
  • Team discussions
  • Team reviewers

To know more about these features go through the GitHub documentation about these features.

GitHub commands

These are some basic Git commands that will help you.

  • Sets the name and email of the author.
git config -global user.email"[email]"
Code language: Tcl (tcl)
  • Starts a new git repository.
git init [repo name]
Code language: Tcl (tcl)
Here I created an empty repository on my device.
  • Copies repository from URL.
git clone [URL]
Code language: Tcl (tcl)
  • To create a new file
touch "filename.extension"
Code language: Tcl (tcl)
I created a new text file named new.
  • Adds all the files to the staging area.
<code>git add *</code>
Code language: Tcl (tcl)
I added the file to the repository.
  • To open the file
vi "filename.extension"
Code language: JavaScript (javascript)
I opened the text file.
After opening the file I added a new line “Hello world” and a bunch of new empty lines. To exit the file press escape and type :x! and press enter.
  • It shows files that can be committed.
git status
Code language: Tcl (tcl)
It shows us that the file new.txt can be committed.
  • Records file in the version history.
    • Using commit command you can save your file after every modification and can go back to visit it.
git commit -m [message]
Code language: Tcl (tcl)
I committed the file after adding a bunch of new lines and put a message “new line added”, so whenever someone checks history the commit will be shown with the message.
  • It shows the version history of the current branch
<code>git log</code>
Code language: Tcl (tcl)
When checking the version history it shows the commit id, author name and associated email ID, date and time and the message.
  • Undo all commits.
git rest [commit]
Code language: Tcl (tcl)
  • Displays changes made in files.
git diff
Code language: Tcl (tcl)
  • Shows all the branches present in the repository.
<code>git branch</code>
Code language: Tcl (tcl)
  • Creates new branch.
git branch [branch-name]
Code language: Tcl (tcl)
  • Deletes the branch.
<code>git branch -d[branch-name]</code>
Code language: Tcl (tcl)
  • Switches from one branch to another.
<code>git checkout[branch-name]</code>
Code language: Tcl (tcl)
  • Upload local repository to remote repository.
<code>git push</code>
Code language: Tcl (tcl)
  • Imports remote repository to local repository.
<code>git fetch</code>
Code language: Tcl (tcl)

The last two commands are the most important and I already explained why you use them.

Some more basic Git Bash terminal commands

Conclusion

I hope this blog was sufficient to make you understand what Git and GitHub are. The whole concept of Git and GitHub might be hard for you to understand at first but trust me it gets easier when you start working with it.

Sharing is caring

Did you like what G Praveen wrote? Thank them for their work by sharing it on social media.

0/10000

No comments so far