Ishita Keshawani
Ishitakeshawani

Ishitakeshawani

Learn Git and Github in 5 minutes

Learn Git and Github in 5 minutes

Ishita Keshawani's photo
Ishita Keshawani
·May 20, 2022·

5 min read

Hello Everyone, In this blog, We will discuss using Git and Github, various git commands, and their use. We will learn to create a repository, push code, create branches, issues, etc in giithub. So let's start it!

What is Github?

Github is a Cloud-based hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. You host your project in the repository and showcase your skills and learning. Let's learn how to use GitHub.

Create Repository

The repository is like a folder in which you can put files, folders, images, spreadsheets, Anything. In the Repository, you can add a readme file in which you can give a description of your project.

  1. In the upper right corner, next to your avatar, click + and then select New repository.
  2. Name your Repository and give a short description.
  3. To initialize the repository with Readme you can select Initialize this repository with a README. In the Readme file, you can put a description, screenshots, and demo video of your project.

Screenshot (251).png

Creating a New File

  1. Go to Add file and Click on Create new file.
  2. Give a name to your file and Write Information you want to add to the file.
  3. You can preview your file by clicking on the preview.
  4. Go to commit the new file and add a commit. Commit is a message which describes changes or works you have done and a user can understand why and what have you done.
  5. Click on commit new file.

Create a branch

Branching is the way to work on different versions of a repository at one time. By default, your repository has a branch named main. Let's take an example: your application's code is in the repository and it is in the main branch. now you want to add another feature to your application so you should not directly add it to the main code. so you can make another branch and add your feature to that branch. If that feature works fine then you can merge it into the main branch.

To create a new branch

  1. Go to your repository.
  2. Click the drop-down at the top of the file list that says branch: main.
  3. Type a branch name, Your Branch Name, into the new branch text box.
  4. Select the blue Create branch box or hit "Enter" on your keyboard.
  5. the Second branch is a copy of the main branch now you can do changes to others.

image.png

Open a Pull Request

If you want to propose a change in another's project or you want to merge your second branch's code in the main branch it is possible with an open pull request.

  1. Go to the Pull Requests tab and click on the new Pull Request.
  2. Select the branch you want to compare with the original branch.
  3. Give a short description of why you want to make PR and click on Create Pull Request.

image.png

Merge Pull Request

When Someone did PR(Pull Request) in your repository and added necessary changes and you want to merge it in your code then you should merge it.

  1. Click the green Merge pull request button to merge the changes into the main.
  2. Click Confirm merge.

Create Issues

Issues are features or changes that can be proposed by viewers in your code. When you find some bug or cool feature for anyone's repository then you can create an issue in that repository on the issues tab and click on New Issue.

image.png

If you want to solve issues in someone's project then go to the issue and ask to assign the issue to you. Congratulations! You learn how to use Github.

image.png

Let's learn GIT

  • Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
  • Real-life projects generally have multiple developers working in parallel. So a version control system like Git is needed to ensure there are no code conflicts between the developers.

The first time while using git you should set up your name and email address using the below commands.

git config --global user.name "abc"
$ git config --global user.email abc@example.com
  • Go to Git and in your folder which you want to host on Github.

image.png

  • git init command adds a local Git repository to the project.

Staging and committing code

  • First, you need to do staging your code. It is for keeping a record of files that you have added.
  • Files that are not added to the staging area can not be committed.
  • git status is the command for that.

image.png

  • For adding all files to the staging area write the command git add.

image.png

  • Committing is the process in which the code is added to the local repository.
  • git commit is the command for committing and the first commit is the message.

image.png

Add remote origin and push code

  • Every change you have made is in your local repository. It will not reflect on GitHub until you add remote origin and push your code. add your remote repository URL by git remote add origin URL(of the remote repository)

image.png

  • git remote -v command is for checking URLs of a connected remote repository.

image.png

  • Now you can push your code to Github from your local repository to Github using the git push -u origin master command.

image.png

Now you can watch your project file on the Github repository like below.

image.png

Status

git status shows which files are modified and which are in the staging area. Files that are in the staging area are shown green and files that are modified but not put in the staging area are shown red.

Log git log command prints all commits till now.

Create Branch

For making a new branch use the git branch test command. The test is the name of your new branch.

Switch to another branch

Git checkout main The command for the switch to another branch main is the name in which you want to switch. After using the above commands and doing practice you can easily host your projects on Github.

image.png

Clap 👏 if you find this blog helpful. See you at the next one!

 
Share this