DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Why and How Git ?
Abhishek kushwaha
Abhishek kushwaha

Posted on

Why and How Git ?

Git is a software that tracks changes in any initialised repository or directory. It's helps for coordinating with your fellow programmers to collaborate and for tracking changes in any set of files.

Git was created by Linus Torvalds in 2005 for development of the Linux kernel, and it’s now a fundamental developing tool that’s used by almost all professional developers.

Git mainly help us in these two following terms :

  1. Collaboration
  2. Having A record of changes and previous state of code.

Many new developers and students have an confusion between Git and Github.
Let's understand how they are different :

Git is a version control system that keeps track and maintains a log of all the changes that are committed by the changer.

Whereas ,
Github ia a company that provide hosting services for the code and repository and let people collaborate which internally uses git for operation.

Git Installation

To get started with git and explore version control system we firstly have to install git locally in the system for that head over to Git Download and have a installation for your desired operating system.

The process is straight forward and with couple of next click and you are ready to head over to Git BASH.

The above picture shows the git bash screen which is the terminal which uses bash language for scripting.

The above picture shows the git bash screen which is the terminal which uses bash language for scripting. Before using some git commands and exploring the git features, let's first walk through some command cli commands which would help one getting use to terminal.

  1. pwd command : The shell command pwddisplays the file path from the root directory to the current working directory.

pwd

  1. mkdir Make Directory: The shell command mkdir is used to make a new directory in the filesystem according to its argument. If a file path is given, the new directory will be placed at the end. Otherwise, it creates a new directory in the current working directory.

mkdir

The Directory is added to home path to view the folder one can use GUI Application , but we are developers so 😎

  1. ls List: The shell command ls is used to list the contents of a directory. If no arguments are given, it will list the contents of the current working directory.

ls

The above folder that We created is present in the folder can be found in the picture shown below :

folder can be seen

  1. cd Change Directory : The shell command cd is used to move throughout the filesystem of a computer.

cd

cd accepts a variety of arguments:

  • Full file paths leading to some directory.
  • Name of children Directory
  • .. To move to parent directory of the file.

You can learn More of these basic cli commands here ➑️ Click me

Git Initialising

Before initialising lets check what version git is being installed in our system through this basic command :

$ git --version
Enter fullscreen mode Exit fullscreen mode

git version

To work with git we need some config for the user details as it manage the log associated with the changer maintaining the changes.

To set those we simply set git configs like username and email for the user. To do so follow these commands :

$ git config --global user.name "YOUR_USER_NAME"
Enter fullscreen mode Exit fullscreen mode
$ git config --global user.email "YOUR_EMAIL"
Enter fullscreen mode Exit fullscreen mode

After setting up you can check if they are configured well or not through these commands :

git -config --global user.name
git -config --global user.email
Enter fullscreen mode Exit fullscreen mode

These would return your given values or string.

git configuration

Now we are actually ready for the project so head over and create a folder and add any project you want to push over to github and keep a track of changes in git.

git init in folder

As we are done with creating a git repository , its time to add some files and commit the changes to log.😎 For this article am using a simple fronted site .

index.html init

Now lets add these files to commit and then commit with a message "First dev commit" .

First dev commit

We can check all the logs for confirmation πŸ˜€
logs

## Now lets Push this local repository to Github .

To push the code or your work to Github we first have to make a connection between the local repository and remote one for both fetching and pushing operation . For that lets first create a repository an blank one over github .
blank repository

To establish the connection we would be needing the url : https://github.com/Abbhiishek/bookish-giggle.git. These url can be found over your repository or else you just add .git in the last of your repository url from browser.

To make the connection we do :

git remote add origin url_here 

Enter fullscreen mode Exit fullscreen mode

remote add origin

Also to view the connection that are established we can use :

git remote -v 
Enter fullscreen mode Exit fullscreen mode

Now as the connection is established we would be pushing to github all the committed stuffs from local to remote repository .
To do so we do we have the command :

git push origin <branch_name>
Enter fullscreen mode Exit fullscreen mode

pushing

We can see Github is updated with the pushed code
why git and github

Hurray πŸ₯³

Though this article was not intended to give you whole idea how to work with git , I tried my best to make things understandable. If Found helpful let me know in comment section.

In the next article would share how to push it to Github Pages or other services like vercel or netlify .πŸ“

kudos !

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.