Essential git CLI commands


Frequently used commands:
git init
# initializes.git add .
# adds all filesgit add <file 1> <filel 2>
# adds individual file.git commit -m "descriptive message."
# commitsgit branch <branch name>
# creates a new branchgit checkout <branch name>
# checkouts to a branchgit branch -n <branch name>
# creates new branch and checkoutsgit merge <branch_name>
# checkout to the main branch, then mergegit checkout main/master && git merge <current branch>
# merging from being in the branch to be merged.git pull origin <branch_name>
# pullgit 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 branchgit 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
Subscribe to my newsletter
Read articles from Meeran E. Mandhini directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Meeran E. Mandhini
Meeran E. Mandhini
Hello, I'm Meeran E. Mandhini from Chennai, India, with a deep interest in technology, especially personal computers. My love for tech has inspired my children, especially my son Ashik Nesin, who dreams of starting his own software company. He started working towards this dream at just 13 years old. Now, I'm excited to dive back into my own interest in software development. The progress in artificial intelligence has made it easier for people like me to learn programming and software development. With my son's knowledge and the power of AI, I'm ready to delve into the software development world. Through this blog, I'll share my journey, experiences, and insights. I hope to connect with other budding developers and contribute to the software development community.