Hello my friends.

This is my first post and I was thinking what I should write in my first post. Then suddenly I realized that in the beginning of my college time, I faced so much problem in github. I was very much confused how to use that.

In this post I am going to explain github in a very quick way, so that you can start using github. So let’s do it.

# Signup in github

Visit github and create an account. If you have one already, then you can ignore this step.

# Installation

  • Windows

Visit download git and download the .exe file. and install it.

  • Ubuntu

run these command in terminal

sudo apt-get update

sudo apt-get install git

# Setup

Now you have installed github in your machine. Before moving ahead we have to configure github.

  • Setting your global configration. Whenever you will push anything in the github, it will reflect this name/email.

git config — global user.name “Your Name”

git config — global user.email “youremail@domain.com”

If you are managing more than one github, than you have to use seprate configration for each repository/project.

  • Setting your local configration for each project/repository. Goto in your project directory.

git config user.name “Your Name”

git config user.email “youremail@domain.com”

After this, your directory will be assign with this local configration.

# Setup View

  • For Global

git config — global user.name

git config — global user.email

  • For Local

git config user.name

git config user.email

# Create repository

Visit New repository in github. Put repository name and little description and press Create repository button.

After create, open your repository and click on the green button Clone or download. Copy the link.

Open your terminal, goto a suitable directory where you want to create your local repository/project.

Dont create a directory with your project name, because github ig going to manage this. So you can chill out.

run this in terminal

Note: please dont add quote in copied link.

git clone “Your copied link”

After doing this, you can see your directory.

Now the main part is starting from now. There are two repository. First one is in your local machine and the another one is in github. whatever the changes you will do inside the repository, it will be happen in your local. for put those changes in the github server we have to push our code.

# Status

For checking your repository status any time, just run this command.

git status

It will show all the file which are changes in your local.

# Steps

Create any new file inside your local repository and save it and run git status. You can see the modified file details.

You have to understand that right now your changes is in local.

  • If you want to check your changes details then run this command

git diff

It will show you in each file where you have change with respect to your local.

  • For saving your changes in your local, type

git add .

It will add your file in ready to save in local.

Now for put these changes in local repository then type,

git commit -m “Your message which describe your changes.”

After this if you will check for status it will show that by how many commits your local repository are behind by github server.

Please note that, right now you have saved your changes in your local repository. for put these in github you have to push.

It is a good way that before pushing anything to github, please pull your code

# Pull

Type this for pulling your code from github to your local. your default branch is master.

Note: please dont add quote in branch name.

git pull origin “Branch name”

After running this you have all the latest code which is in github server. Now you are ready to push.

# Push

Note: please dont add quote in branch name.

git push origin “branch name”

Now your changes are in github server. You can check in your github account. Open your repository in github, and go to commit tab, there you can see your commit details.

# Conflict

After add and commit when you will pull the code, then sometimes conflict happens. When more than one person are working in the same repository then this happen generally. Suppose person 1 has edited file 1, and person 2 has also edited the file 1, that time github cannot recognize which code it has to take, so it show conflict.

Resolving is very easy. Just open your file in which your conflict are showing. you can check it by git status also.

Seach for <<<< or HEAD in that file.

  • Basic format of conflict

fix your code and remove <<<<, ===== and >>>> line.

check for status. if it is not showing conflict, then you are good to go. You have to again add and commit your changes after fixing your conflict.

Conflict also happen when you merge your branch.

# Branch

To check your local branch

git branch

To check your local + github branch

git branch -a

If you want to create a new branch then you have to first goto your base branch from where you want to create new branch.

eg: suppose from master branch you want to create new branch master_testthen you have to first goto master branch.

  • For move one branch to another

git checkout “branch name”

Note: branch name will be without quote. This command will switch your branch which are locally present in your machine.

Suppose a branch is newly created and it is in github, then first you have to bring that new branch in your local git.

for fetching any new changes from github.

git fetch — all

this will fetch all the new thing in your local machine.

After that you can move to that new branch with checkout command.

For creating new branch

git checkout -b “branch name”

Note:branch name will be without quote. This command will create a new branch and switch into that branch at the same time.

# Merge

Suppose you are working in branch A, after that you want all of your code in branch B, then for this you have to merge your code.

For merging your branch, you have to checkout to that branch in which you want to merge. For eg: If you want to merge branch A to branch B then you have to checkout to branch B. Then you have to run merge command.

git merge A

A is branch name. Be carefull while merging and be sure that you have pulled the latest code before merging.

Sometime conflict happens while merging, you can easily fix your conflict as I have explain above.

Thanks for your time,

Written by

Busy in learning new things.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store