Git commands one should know!
Viewing branches :
git branch --listCreating a branch :
git branch [branch name]Switching from one branch to another :
git checkout [branch name] Deleting a branch :
git branch -d branch_nameGit config :
• It sets the developer name and email address with pushed commits on github.
git config --global user.name “[name]” git config --global user.email “[email address]” Git status :
• Git status gives information about the branch & files
git statusTo check push/fetch origin URL :
git remote -vgit init :
• Git init helps to start a new repository
git init [repository name]Git pull :
• To gets the updates from remote repository and immediately applies the latest changes in your local.
git pull origin main/masterGit clone :
• Git clone helps us to download repository via URL from github.
git clone [url]Git add :
• Git add helps us to adds a file with filename or totalfile to the staging area.
git add [filename]git add .To undo the changes :
• We need to specify the hash code ( eg. 3321844 ) next to our commit that we would like to undo
git revert hash_codeTo rename a git file :
git mv old_file_name new_file_nameTemporarily stores your modified files :
git stashView all of your stashes :
git stash listApply a stash to a branch :
git stash applyTo see all the previous commits :
• Most recent will appear first
git logTo see commits of other group authors. :
git shortlogTo see details about a specific commit :
git show your_commit_hash_codeTo delete tracked file from the current directory :
git rm file_nameTo merge a specific branch feature to your directory :
git merge branch_nameTo integrates two branches into a single branch :
git rebase base_nameTo find a good/bad commit :
• Initiate git bisect
git bisect startTo know about a good commit :
git bisect good a123To know about a bad commit :
git bisect bad z123To apply a commit from any branch and apply it to any other branch :
git cherry-pick commmit_hash_codeTo compare two Git files :
• To compare working directory with the local repo
git diff HEAD file_nameTo compare two branches :
git diff source_branch target_branchTo compact all commits in one commit :
$ git rebase -i HEAD~3pick 3123cb90
squash 8560f5fb
squash 70644096There are many commands in Git :
• To compare working directory with the local repo
git help