Introduction To Git And Git-hub

Introduction To Git And Git-hub

Are you Into programming and enthusiastic to learn about git and git-hub? Working on a project and have to connect with other members of the team?

If yes, then this article got you

Once you’re done with the article, you’ll get to know about stuff like creating your own repository, creating branches and how to make changes to them, creating push and pull requests and a lot more. You’ll also get to know about the commands that are frequently used while working with git. in this article, we’ll only be covering the basics of git. There’s a lot of stuff to learn if you want to use Git and GitHub like a pro, of course. You can go way beyond this introductory information! I’m going to leave the next-level stuff for another time, though.

What is Git?

Git is a free and open-source distributed version control system for tracking changes in source code and is used for software development. It allows you to record changes in your file over time so that you can access specific versions of your file later on. So git is basically a content tracker.

In summary, this is what git does:

1.Record changes in your project and its files

2.Revert back to previous states at different points in time

3.Collaborate with multiple people on one codebase

4.See changes over time

.5.Develop multiple features at once

Then what is git-hub? Do they relate closely with git? Check out below

GitHub is a Git repository hosting service, but it adds many of its own features. While Git is a command-line tool, GitHub provides a Web-based graphical interface.

Creating a repository

As per the Oxford dictionary, a repository is a place where something is stored in large quantities. a person or book that is full of information.

Follow the steps to create a repository on GitHub

1.GitHub website, look in the upper right corner, and click the + sign and then click “New repository.

2.Name the repository, and add a quick description.

3.Decide whether you want this to be a public or a private repository

4.Select “Initialize this repository with a README” option if you want to include the README file. (I definitely recommend doing this! It’s the first thing people are going to look at when they check out your repository. It’s also a great place to put information that you need to have in order to understand or run the project.

Kudos! you have created a new repository

Follow the steps to create a repository using git CLI:

1.Head over to the folder where you want to create a repository and create a folder with the respective name.

2.Go into the directory

3.Type git init

This was easy and simple though !! :-)

##Now, since we had skipped the cloning part of the repository, let's learn about that also.

If a project has already been set up in a central repository, the git clone command is the most common way for users to obtain a development copy. Like git init, cloning is generally a one-time operation. Once a developer has obtained a working copy, all version control operations and collaborations are managed through their local repository.

1.To clone a repository means that you’re taking a repository that’s on the server and cloning it to your computer — just like downloading it. On the repository page, you need to get the “HTTPS” address.

2.Copy the address and use the following command on your terminal :

```cd "repository-name"

## Basic Version Control

-Navigate to the directory in which you had cloned the repository, using the standard “cdcommand. Now you can initialize a git repository with the following command:


```git init

This creates a new subdirectory named .git that contains all of your necessary repository files — a Git repository skeleton. At this point, nothing in your project is tracked yet.

To start versioning new or any existing files, you should start by tracking those files and doing an initial commit. To accomplish that, you start by adding the files to git that you would like to be attached to your git project.

As of now, you won’t be having any file in this repository because you haven’t created any. So, create a sample text file in the very same directory and name it test.txt

Now to add this file, enter the following command:

```git add "file-name"


To add the files in your working directory, you can use the following command :


```git add --all

##How to make your first commit in git?

```git commit -m "commit-text"


 If you want to commit all the files to the local repository with the same commit text, then you can use the following command :


```git commit -am "commit-text"

##Pushing updates to the local repository

For this purpose, we use the git push command. The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. After a local repository has been modified a push is executed to share the modifications with remote team members.

git push origin master

So now you have a GitHub repository and you know how to add files and changes to it! Congratulations!!

So now, you know how to use git and GitHub, how to create a repository and how to make commits to your local repository.

In the next post, we’ll be talking about The main game of git and GitHub: collaboration. That means that we’ll learn how to create branches, checking out of them and then finally merging them into the main branch or any other branch that we want. In addition to this, we’ll also cover some of the advanced commands that we can use while working with git to make it much easier. There’s a lot of stuff that you can do with git, it’s just that you haven’t explored it all.

I’d love to hear about your suggestions if any in the comments section.