# Essential git CLI commands

Frequently used commands:

* `git init` # initializes.
    
* `git add .` # adds all files
    
* `git add <file 1> <filel 2>` # adds individual file.
    
* `git commit -m "descriptive message."` # commits
    
* `git branch <branch name>` # creates a new branch
    
* `git checkout <branch name>` # checkouts to a branch
    
* `git branch -n <branch name>` # creates new branch and checkouts
    
* `git merge <branch_name>` # checkout to the main branch, then merge
    
* `git checkout main/master && git merge <current branch>` # merging from being in the branch to be merged.
    
* `git pull origin <branch_name>` # pull
    
* `git push origin <branch_name>` # push to web repository.
    
* `git branch -d <branch_name>` # removing a branch.
    
* `git status` # check status.
    
* \`\`git remote set-url\` # To rename your local Git repository to match the name of the remote repository,
    
* `git rm --cached .env` # If the `.env` file was already tracked by Git before, you’ll need to remove it from the index, and do the following:
    
    * `git add .gitignore` `git commit -m "Add .env to .gitignore"` `git push`
        
* `git branch` # to see local branches.
    
* `git fetch` # before listing remote branch, run this.
    
* `git branch -r` # to see all remote branches.
    
* `git branch -a` # to see both.
    
* `git branch -vv` # to see both in detail or.
    
* `git branch -vva` # to see both in detail.
    
* `git checkout -` # to checkout last branch.
    
* `git branch -m <new name>` # to rename current branch
    
* `git branch -m old-branch-name new-branch-name` # to rename a branch.
    
* `git push origin -u new-branch-name` # push the new branch to remote
