Git and how to use it.

Git and how to use it.
5 (100%) 1 vote

  3 minutes

It was around 3 years back, I was with one of my seniors , I asked him what is github? The answer was it is a website and don’t you mix it with git. Then obvious next question was then what is git. His answer “Git is used for version control” And that is the statement I still remember.

1. In short Git is used for Version Control.

2. Git is a software that is used to maintain repository(your codes) and made it possible for many users to work at the same time.

3. You can revert your code anytime

4. You can work on many branches at the same time (like software for different schools)

5. As the your code(say software ) evolves, you can release new versions from git , maintaining all the information of the previous versions and bugs and issues.


Lets start with basic functionality:

1. Git init:

It is used to initialize a folder as a git repository.


2. Add :

It is used to add the new files that you create.

Syntax :

your_repository_folder>> git add filesname

For adding all files :

 your_repository_folder>> git add .

3. Commit:

It is just like indexing . This command will index your changes and will not make any change in the main repository. It only changes locally. When you push (which will come further) the changes will be published to the main repository.

Syntax:

 your_repository_folder>> git commit -m "comment "

4.Push:

It is for making permanent changes to the source code.You can still revert to previous code

Syntax:

git push --all

I will suggest this –all


5.Pull: Fetch from and merge with another repository or a local branch

Syntax:

git pull

** before using anything like git pull –rebase please please take a look what harms it can do.


6. Clone

It is used to clone  the git repository at any folder for making changes. It makes a new fork and only admin can allow to make the modification in the main Branch.

Syntax:

 git clone repository_location your_folder_location

These are Basic Operations that you must know if you are in software industry.

Now an example to show how to make a local repository

First you need to create a bare repository on H:. With git you usually name your bare repository with .git, so projectname.git in this case:

 >> cd \Projects\ mkdir projectname.git cd projectname.git git init --bare

When this is done you change to c to create your repository:

 >>  cd \Users\xxx\AptanaProjects\projectname git init git add . git commit -m "First commit"

After this you need to setup the bare repo on h: as the remote repository so you can push up the code you just commited to the repo on c.

 >> git remote add origin H:\Projects\projectname.git git push origin master

Now, someone else can clone from H: to get your changes, and their repos will automatically be setup with the repo on H: as their origin.

Here are Few Websites that provide free git hosting:

Githubmaking repository is free but code is visible to others. there are payment method also. (very famous in open source)

BitbucketFree private hosting upto 5 members i thinks.

GitlabAll free I guess.

Thats all for today.

I will suggest to make a git repository for all your c programs . You will learn how to use git .

https://www.learnsteps.com/git-best-practices-mistakes/

 


Gaurav Yadav

Gaurav is a Full Stack Web Developer and Blogger. Sportsperson by heart and loves football. He has experience with various frameworks in php, python and javascript. Loves to explore new frameworks and evolve with the trending technology.

Leave a Reply

Your email address will not be published. Required fields are marked *