Skip to content

Git Basic Commands

Terminal window
git clone <branch_url>
# Example
git clone git@github.com:maratib/learn-react-native.git
  • b stands for branch
Terminal window
git checkout -b <branch_name>
# Example
git checkout -b add-login-feature
  • d stands for delete
Terminal window
git branch -d <branch_name>
# Example
git branch -d add-login-feature
Terminal window
git push origin <branch_name>
# Example
git push origin main
Terminal window
git pull origin <branch_name>
Terminal window
git checkout <branch_name_in_which_you_want_merge>
git merge <branch_name_which_you_want_to_merge_in_current_branch>
# Example : lets suppose you want to merge add-login-branch to main branch
# First change to main branch
git checkout main
# Then merge the other branch to main
git merge add-login-feature
CommandDescriptionExample
git initInitialize a new Git repositorygit init
git cloneClone a remote repositorygit clone https://github.com/user/repo.git
git statusShow the working tree statusgit status
git addAdd files to staging areagit add file.txt or git add .
git commitCommit changes to repositorygit commit -m "Commit message"
git pushPush changes to remote repositorygit push origin main
git pullFetch and integrate from remote repositorygit pull origin main
git fetchDownload objects from remote repositorygit fetch origin
git branchList, create, or delete branchesgit branch new-feature
git checkoutSwitch branches or restore filesgit checkout develop
git switchSwitch branches (newer alternative to checkout)git switch develop
git mergeJoin two development histories togethergit merge feature-branch
git logShow commit logsgit log --oneline
git diffShow changes between commitsgit diff HEAD~1
git stashStash changes for later usegit stash or git stash pop
git remoteManage remote repositoriesgit remote -v
git resetReset current HEAD to specified stategit reset --soft HEAD~1
git revertRevert existing commitsgit revert abc1234
git rmRemove files from working tree and indexgit rm file.txt
git mvMove or rename a filegit mv old.txt new.txt
git tagCreate and manage tagsgit tag v1.0.0
git showShow various types of objectsgit show abc1234
git configConfigure Git settingsgit config --global user.name "Your Name"
git helpDisplay help informationgit help commit