Getting Started with 'Git'
Tags: beginners, github, git
Published: 2021-06-27 11:49:29

In this Blog i'll cover some basic commands of git, using that command you can easily work with git and Github as beginner.

- Before starting this this blog I want to mention that `Git` and `Github` are not same. many people are understandably confused😕 between this two words at their beginning.

#### GitHub is a website for hosting projects that use git for version control.
<hr>

## What is `git` ?
- Git is a version control system (VCS) that makes easier to track changes to files(code). For example, when you edit a file, git can help you to determine exactly what changed in your file, who changed that file, and why change that.
- Git is a command line tool. it is very useful when we are working on team project or multiple people working on same project

## What is `github` ?
- GitHub is a Git repository hosting service, but it adds many of its own features. GitHub provides a Web-based graphical interface. It also provides access control and several collaboration features
- Git also helps us to store our code safe and secure🔐 and many people use git and github daily to track their daily work. It makes them different from others.
<hr>

## Installation 
- To use git we'll need to download and install git on our system by using [git](https://git-scm.com/downloads). There are both options are available in market. command-line interface(CLI) and graphical user interface(GUI) as Github desktop but I recommend CLI for beginners.

- After installation to check if git was installed properly or not execute the command:
``` bash
git --version
```
<hr>

## First step after Installing Git
- The first thing you should do when you install Git is to set your user-name and email address. This is important because every Git commit uses this information
- you can set your user-name and email using this commands and  also change them at any time
``` bash
git config --global user.name "<User-Name>"
git config --global user.email <Email>
```
<hr>
## Create local git repository
- We'll require git repository to use functionalities of git by using given command.
``` bash
git init
```
- This'll create hidden `.git` folder in current directory. this is the "repository"(or repo) where git stores all of its internal tracking data. Any changes you make to any files within the original folder will now be possible to track.
- The original directory is now referred as working directory.
<hr>

## Staging 
The staging area (aka index) is a container where git collects all changes which will be part of the next commit.
- use below showen comannd to add individual files into staging area
`git add <File1 path> <File2 path>...`
``` bash
git add README.md app/*.txt
```
we also stage all changes together
``` basg 
git add -A
OR
git add .
```
<hr>

## status
`git staus`
- Above command is very useful. It gives overall status of working git directory
- The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.
<hr>


## Commit
The "commit" command is used to save your changes to the local repository. we also need commit message it is important to help other people understand what was changed and why you changed it.
``` bash
git commit -m " <Commit message> "
```
<hr>

## push
The `git push` command is used to upload local repository content to a remote repository.

- But there is one problem. we can't push directly our local repository to remote repo. in Order to do that first we need create repository on githuib and configure that remote repository with local repository. let's see how
- `git remote add <remote_name> <remote_repo_url>`
``` bash 
git remote add origin https://github.com/bhavinvirani/my_repo.git
```
after creatig a repository on the GitHub, You will find the link on that repository itself

Now, we can push our data on remote repository using this command
- `git push <remote_name> <remote_branch_name>`
``` bash
git push -u origin master
```
- If you are pushinga local branch for the first time on a remote, the "-u" option is helpful. It makes sure that a tracking connection between the local and your remote branch.
``` bash
git push
```
- After having set tracking connection, you can perform future pushes without providing additional options - since the tracking connection provides default values for the push command.

<hr>

### Here i Show whole flow of git commands
``` js
git init
// make same changes in working directory
git add -A
git commit -m "made some changes in working directory"
git remote add origin https://github.com/bhavinvirani/my_repo.git
git push origin master
```
<hr>

# Conclusion
In this blog we learned basic command of git and how to push our local repository to remote repository, It is good to use git and github daily to track our code or data.

Stay tuned for some advanced git commands and topics like branches and operations with remote repository which I cover in next article of this series
<hr>

### checkout my `Github 👁`
{% github bhavinvirani/bhavinvirani%}