Introduction To Basic Git Commands

Git/Github is a very powerful version control management tool used by the developers to manage the source code of the projects. In this blog post, we have listed all of the basic Git commands along with the short description of their usage.

  • git init (used initiate a git repository)
  • git add file-name (used to add the file to a staging environment)
  • git add . (used to add all files to a staging environment)
  • git commit -m “first version release” (used to push the changes from a staging environment to the tracked list)
  • git checkout file-name (used to get the previous version of the file back from the staging environment)
  • git reset HEAD file-name (used to un-stage the file changes)
  • git status (used to check the status of the files to be staged or the files to be committed)
  • git log (used to check the history of the commits)
  • git rm filename (used to remove the file and push the changes to a staging environment as well)
  • git checkout hash (used to get back to the previous commit by using a unique hash number)
  • git branch (used to see all branches)
  • git checkout branch-name (used to switch to the specified branch i.e. branch-name)
  • git branch branch-name (used to create a new branch named branch-name from current branch)
  • git merge branch-name (used to merge changes from branch-name into the current branch)
  • git branch -m branch-name new-name (used to rename the branch from branch-name to new-name)
  • git branch -D branch-name (used to delete the branch i.e. branch-name)
  • git clone github-url (used to clone an existing github repository from the specified URL i.e. github-url)
  • git branch -a (used to see all branches of the cloned github project)
  • git checkout -b branch-name origin/branch-name (used to switch to another branch i.e. branch-name of the cloned github project)
  • git clone –mirror github-url .git (used to clone .git folder of the github repository from the specified URL i.e. github-url)
  • git config –bool core.bare false and git reset –hard (grab all branches and copy in the current folder from the above-cloned repository)
  • git clone -b branch-name github-url (used to clone specific branch from the specified github project i.e. github-url)

Leave a Comment

Your email address will not be published.