Git tutorial for begginers.
Tags: git, github, versioncontrol, webdev
Published: 2021-02-02 04:00:29

After reading this post, you will become a master of git/ version control. So let's get started.
<h2>What is Git?</h2>
<p>Git is one of the most popular version control system. It is used for tracking changes of the files from your local computer. And if you are using github or want to use, you should know how to use git for version control. It's really useful. More ever if you are applying for a interview you should have this skill in your resume. Git is not a complex stuff like a programming language. You only need to memorize some commands to use git. Just not memorize them try to realize how it works then it will be more easy. So let's install git.</p>
<br/>

<h2>Installation</h2>
<p>Before using git, you need to install it in your computer. You can install it very easily from the official website of <a href='https://git-scm.com/downloads' target='_blank'>Git.</a> Installation process is very easy. Next, Next and install.</p>
<img src='https://dev-to-uploads.s3.amazonaws.com/i/cush3yimrxkexattu43s.png' alt='install git' />
<br/>

<h2>First Command</h2>
<p>After installing git you will get a CLI ( Command line interface ) for using git which is named, 'Git Bash'. Now open up git bash. And let's check if git is installed properly. Try to run this command.</p>
```command
git --version
```
<p>Then if you see something like here in the image, congratulations git is succesfuly installed in our local computer.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/30q6o5yza3m165jpsvog.PNG)

<h2>Setup</h2>
<p>Before using git, we need to set up our work space. Now run this command on git bash</p>
```
$ git config --global user.name "Write you name here"
$ git config --global user.email "Write you email here"
$ git config --global core.autocrlf true
```
<br/>
<p>The last command is important for using git. So paste it in your command line and press enter. Now our git environment is ready for the first use. Let's create a repo on github</p>
<br/>

<h2>Create your first project</h2>
<p>Now got to <a href='http://www.github.com'>Github</a>. If you have a account that's good. If you don't create one it's free. Now click on the plus icons from the top of the page and select new repository.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/iame47uhxpzdurrmutl6.PNG)

<p>Give a repository name.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3vh70016eu9zpk8znxtj.PNG)
<p>And skip the other stuffs for now.</p>
<p>After the repo is created, you will be redirected to this page. </p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tzb1byp7e9nccj7prgx7.PNG)
<br/>
<p>Now go to file explorer. Create a folder for your project.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/k4b9oiovu9wrlyaqzols.PNG)
<p>Now open up git bash. Hope you are already familiar with the power shell/ CMD commands. So I am not going to explain them. In this article I will only talk about git commands. After the git bash is opened, now go to your project directory.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pde2qceyyrare6shrcya.PNG)
<p>Then run this command</p>
```
$ git status
```
<p>Then it will show this output.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x1vei6gfhyq4b2ei9hay.PNG)
<p>It means this is not a git initialized repository/ folder. Now we have to initialize this folder as a git repository. So run this command below in your git bash.</p>
```
$ git init
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/y4hxshtt9mxob219mpgy.PNG)
<p>Now our this folder is a git repository. Let's create a file under it.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pn6ixr496n30wd65ct0f.PNG)
<p>I have created a html file under it you can create what ever you want. Now open up git bash and check status.</p>
```
$ git status
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b7r0ianerwy706j26dis.PNG)
<p>So as you have seen index.html is a untracked file. Now we have to put it into the staging area. So the command to stage all files is </p>
```
$ git add .
```
<p>It will stage all the files in the folder. If you want to stage the index.html only you can run this command.</p>
```
$ git add index.html
```
<p>Or if you want to stage all the .html files only, you can run this command.</p>
```
$ git add *html
```
<p>So now try to check the status again. Now you know how to check the status with command.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xdrj6ogb4inwy3pyxqeg.PNG)
<p>Now it's showing that all the files are now in the stagging area. Now let's commit out changes with that command.</p>
```
$ git commit -m "Your message for that change"
```
<p>After commiting, Now check the status of your repo.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/0l1cl12wwk17m2i7667i.PNG)
<p>As you can see now we are all set. Now go to your github repo which we have created at the beggining.</p>

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6wepte2ma2xsxnf0baid.PNG)
<p>Now we need to add a remote origin of our github repo to our local repo. After adding that, we will be able to push our files in our online repo. So let's do that. Now copy the ssh link of your github repo.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dspd14hvftaqqrfahn9x.PNG)
<p>Now open up git bash and write that command and then paste you ssh link.</p>
```
$ git remote add origin git@github.com:Ratul-oss/github-practise.git
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yeyr0gb8nscqp39t83zp.PNG)
<p>Now we can push our local files in our online repo. That sounds so interesting right!? So now we have to push our files.</p>
```
$ git push -u origin master
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qoc7sgpcz1scbcnwarbe.PNG)
<p>Here we go. Now go to your github repository page and reload. refresh it. And you will see the magic.</p>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9kyqdbpi4a3cpg7iyg02.PNG)
<p>Tada!! Now our index.html file is public.</p>
<br/>

<h2>Final Command</h2>
<p>This command is a little bit dangerous. Cause this command will uninitialize your folder from a git initialized folder. Let's run it.</p>
```
$ rm -rf .git
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mit0dsdyk0yqqkw4qaa1.PNG)
<p>As you can see now it says it's not a git repository.</p>
<p>Another command I forgot to explain. It's,</p>
```
$ git clone put the ssh link here.
```
<p>By using that command you can clone any repository. Just copy the ssh link. and put it after ' git clone ...'</p>
<p>Another bonus command is, if you want see, how many commits, you have done, you can run this command.</p>
```
$ git log
```
<br/><br/>

<p>So that's how we track files using git. Which is really helpful when we are doing big/ small project. So after you realize everything about git, you will use it daily. Upload your projects on github which will be helpful when you are going for a job interview. If you want to learn more about git I recommend you that <a href='https://youtu.be/8JJ101D3knE'>video</a>. Thanks for reading this post. Hope it helped you. And make sure you follow me to recieve all the informational posts just like that. And if you have any issues regarding that post kindly inform me. I will take the steps which I can.</h3>
<h4> :) </p>