Essential git CLI commands
Here is what I compiled for my workflow.
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