Git commands one should know!
Viewing branches :
git branch --list
Creating a branch :
git branch [branch name]
Switching from one branch to another :
git checkout [branch name]
Deleting a branch :
git branch -d branch_name
Git 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 status
To check push/fetch origin URL :
git remote -v
git 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/master
Git 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_code
To rename a git file :
git mv old_file_name new_file_name
Temporarily stores your modified files :
git stash
View all of your stashes :
git stash list
Apply a stash to a branch :
git stash apply
To see all the previous commits :
• Most recent will appear first
git log
To see commits of other group authors. :
git shortlog
To see details about a specific commit :
git show your_commit_hash_code
To delete tracked file from the current directory :
git rm file_name
To merge a specific branch feature to your directory :
git merge branch_name
To integrates two branches into a single branch :
git rebase base_name
To find a good/bad commit :
• Initiate git bisect
git bisect start
To know about a good commit :
git bisect good a123
To know about a bad commit :
git bisect bad z123
To apply a commit from any branch and apply it to any other branch :
git cherry-pick commmit_hash_code
To compare two Git files :
• To compare working directory with the local repo
git diff HEAD file_name
To compare two branches :
git diff source_branch target_branch
To compact all commits in one commit :
$ git rebase -i HEAD~3
pick 3123cb90
squash 8560f5fb
squash 70644096
There are many commands in Git :
• To compare working directory with the local repo
git help