Beginner🌱 Git Commands
Tags: git, beginners
Published: 2020-10-28 13:18:32

Hi 👋🏻
If you just begin your Git Journey and confused😕 with Git Commands ,Then this is for you :relaxed:!

# Environment setting for Git Bash

If you don't know Git Bash or if you haven't used git in your machine :computer: , follow these steps to get started:

1.Download Git Bash for your device :computer:  [Git Bash](https://git-scm.com/downloads)

2.Open Git Bash  by clicking the right mouse button :computer_mouse: for Windows user. Then set up your name:name_badge: and email:e-mail: ID:

	$ git config --global user.name "<Your_Name>"
	
	$ git config --global user.email "<Your_Email>"

3.Go to [GitHub](http://github.com/) and create your GitHub account using your email.
  Make sure ,to use the same email:e-mail: ,you have used earlier.
 
### At this instance there are two ways to go furthur:

**:one:First**

4.Go to your desired folder:file_folder: your you want to keep all your your GitHub repository:flushed:. 

   *clone a remote repo. via URL*

             git clone URL
  
You may get URL from a online GitHub repository by Clicking on Code
Button :first_quarter_moon_with_face: of Your repository.

**:two:Second**

4.Go to a folder:file_folder: which you want to make as a GitHub repository:flushed:. 

*Initalize a existing directory as a git repo.*
      
            git init

# *That's all for setting ,Now begin your Code*

# :tada::tada:**Commands**:tada::tada:

![Commands](https://dev-to-uploads.s3.amazonaws.com/i/8hugfatccsw4em9vqhyq.jpg)

# 1 : 
 ***Below will add your modified file.***
             
               git add myFile

When you want stage your changes for **myFile** file.


               git add .    Or    git add -A

When you want stage your **All modified** file.

# 2 : 
***Below will restore your file.***
             
               git reset myFile

 unstage a file while retaining the changes in working directory

***Below  will show all commits with all details like author and their email.***
     
                git log

 ***Below  will show  commits in compact way!,Only show commit hash and message***
     
                git log --oneline

# 3 : 
             
               git revert <commit hash>

If you want roll back your commit,You may use above command.
you can get commit hash of all of your commit by entering command: `git log `

# 4 :
***Below will show your current status.***

                 git status


If you haven't staged or add it ,It will show like this

	 On branch master
       Changes not staged for commit:
       (use "git add <file>..." to update what will be committed)
       (use "git restore <file>..." to discard changes in working directory)
        modified:   abcd.md

       no changes added to commit (use "git add" and/or "git commit -a")
   
If you have staged your file. Then, It will show you staged modified file for your next commit.Like this:

     On branch master
      Changes to be committed:
       (use "git restore --staged <file>..." to unstage)
        modified:   abcd.md



# 5 : 
             
                git push origin <branch>

When you want to push  your final changes to remote repository in particular branch.By default ,you have master branch ,so you may
write as:
      
               git push origin master

# 6 : 
             
                git pull

When you want to pull  all changes from remote repository in your current local branch.

# 7 : 
***When you want to create branch***

               git branch branch1

create a new branch name **branch1** at the current commit

***When you want to see all branches***

               git branch

It will list your branches. And a *  will appear next to the currently active branch like this:
    
           PS D:\winter plan> git branch
           * branch1
             master
             one

***When you want to switch branch***

               git checkout branch1

switch to another branch1 and check it out into your working directory
    

# 8 :
***Merge a branch into another or main***

            git merge branch1
            
merge the branch1 history into the current one

*When you want to switch branches either you need to commit your modified changes Or you may temporarly stored modified and tracked file.*

              git stash

***above command Save modified and staged changes and below will discard  the changes from top of stash stack***
  
              git stash drop
      
### Happy Gitting :boom::boom: