Git and Github World! - TechPro

Latest

You will find cool and interesting stuff's as the name suggest its all about the "Tech Programming"

Wednesday, July 29, 2020

Git and Github World!



git-pic

As a beginner its very difficult to gulp the words related to Git and Github.
Like commit, push, repositories and many more.
They seems irrelevant and difficult to fit in our terms, like where they are used, how would I use such a difficult process...
This is a normal fear every beginner face before going to use this super easy 'Git and Github'.

So lets explore-
(Keep patience, its definitely easy, they seems tricky just because of their name.)

What is Git?

Git is a version control system that's lets you manage and keep track of your source code history.

(Now in more simple words its moreover used as a command in your system ...so do not worry much ).

What is version control:- It is a system that records changes to a file or set of files over time so that you can recall specific versions later.(In simple words, if you change/add something to your file's data ,it keeps both ones , the previous as well as updated file).

What is Github?

Github is a cloud based hosting service that lets you manage git repositories.

=> Now lets understand the terms and Commands related to these,

I am cutting this world into 2 (you will hardly require the 2nd one)...
you will on your full speed with the first part...
I also didn't use the 2nd part much, even I only used them ones that's for learning. Since then they are hardly come in use for me.

The first Part:-

  • Repositories It is just a file location,where you store all files connected to your project (you can call it 'project's file folder').

  • Commit - Basically this is a command , used to run on the power shell or command prompt.

    ~what it will do- It is used to save changes to the local repository (local means on your own laptop, p.c. or any other system you are using).

  • Push - This is how you transfer commits from local repository to a remote repository (remote is located on the github, which ultimately store your files online.)

The second Part:-
  • Clone - this generally copy the remote repositories to local repositories (it includes all available public repositories present over the internet. Yes, you can copy them and learn a lot).

  • Fork - It generally copy others repository to your Github, now you can use them without disturbing the original repository.

  • Fetch - Getting latest changes from online repository without merging them in.

  • Branch - It is a temporary sub-folder (you can add them again using merge).

  • Merging - It takes changes from one branch and applies them to another (done through pull request or command line).


If you are thinking clone is very important, then my friend as already stated they are command. When you visit Github, you will find that with just one click you will get the repository downloaded on your system, then why would I go to command line then clone it...(why so critical-always. Always remember- work in your own efficiency, what you seems best fit for you).
well, it's my  particular scenario, but they are very useful in many situations, specifically in the collaboration time.

(Now do not worry much about all these at once, I will give you a straight and effective way to not stuck at any point, as not all of them are going to come in use every time, only few of them come in use always, others are just on requirement).

I hope now you have some clear picture. so lets proceed further...

Set up a Git repository and perform basic Git operations:-

First to install Git on your computer, go to https://git-scm.com/downloads to download the Git installer.

Now if you are using git first time then you have to set some global configuration (only once and you are good to go.)

For checking and conform install of git  (on Command prompt or power shell in window/terminal):
 git --version 

-To configure your user name to be used by Git, type the following at the prompt:
 git config --global user.name "Your Name" 

-To configure your email to be used by Git, type the following at the prompt:
 git config --global user.email <your email address> 

-You can check your default Git global configuration, you can type the following at the prompt:
 git config --list 

that's it...its set ...lets go further...


Set up a folder as a Git repository

(At a convenient location on your computer, create a folder and give it some name. Now your working files/data will be in this folder ).

-Go to the git-test folder in your command window/terminal and type the following at the prompt to initialize the folder as a Git repository:
 git init 

-Type the following at the prompt to check your Git repository's status:
 git status 

-To add files to the staging area of your Git repository, type:
 git add . 

(Here the last ' . ' will add all new/changed files to the repository).

-To commit the current staging area to your Git repository, type:
 git commit -m "first commit" 

-To check the log of the commits to your Git repository, type:
 git log --oneline 

    
Now its time to go online...

Set up the online repository as a remote repository for your local Git repository:
(So, first create a repository online and get its url...as in the shown steps)   

First create account on github then ,you will see a '+' sign symbol on top right corner. click it.
Select 'New Repository' then this page will occur:-

Give it a name, then choose public or private then click green button.
well, your repository is created.

you will see like this in front of you:-
this is your repository URL. Copy this URL.

-At the prompt, type the following to set up your local repository to link to your online Git repository:
 git remote add origin <repository URL>    (You have to add origin every time for a new repository)

Push your commits to the online repository

-At the prompt, type the following to push the commits to the online repository:
 git push -u origin master 

Clone an online Git repository to your computer

-To clone an online repository to your computer, type the following at the prompt:
 git clone <repository URL> 
   

See that's it...I told you it's easy.


 Use of Git and Github

  • Pushing tool:- You can simply put your code, your effort, your practice projects over the Github and showcase your skills, your work. (Now this is the part I like the most, its fun).
  • Version control system:- Every open source project's first approach is toward git, which ultimately manage by Github. Specifically manage the git repositories.
  • For Collaboration:- Now on a big extent, it allows groups of developers to collaborate on same document which is basically a source code of some project , also without overriding each other's work.
  • You also get hosting with Github, that's also one more interesting area of it.


(Now, my friend do not worry much about it, its also not that tough, so first know and focus on the basics, because everything is quiet easy).

Keep Learning...

1 comment:

If you want to convey your thoughts regarding this blog-post, you are most welcome...