Git Commands for Beginners

  • Last updated Apr 25, 2024

Here is a list of Git commands that every beginner should know:

  • To change a directory into a Git repository:
  • git init

  • To copy a project from a remote Git repository to your local repository:
  • git clone <remote_repository_url>

  • To switch between branches in your local Git repository:
  • git checkout <branch_name>

  • To create a new branch in your local Git repository:
  • git branch <branch_name>

  • To create and switch to a new branch using a single command:
  • git checkout -b <new_branch_name>

  • To rename a Git branch:
  • git branch -m <branch_old_name> <branch_new_name>

  • To save an update of a single file for the next commit:
  • git add <file>

  • To save an update of all files for the next commit:
  • git add .

  •  To commit changes of files before pushing updates from a local Git repository to a remote Git repository:
  • git commit -m 'commit message here'

  •  To push updates from a local Git repository to a remote Git repository:
  • git push origin <branch_name>

  • To fetch and download the latest updates from a remote Git repository to a local Git repository:
  • git pull origin <branch_name>

  • To force delete a local Git branch:
  • git branch -D <branch_name>

  • To delete a remote Git branch:
  • git push -d origin <branch_name>

  •  To remove a file update of the next commit:
  • git reset HEAD <file>

  • To save the current state of the working Git branch and go back to previous clean working branch and work on something else so that later you can go back and re-apply the changes:
  • git stash

  • To re-apply the changes in the current working branch, previouly recorded using the stash command:
  • git stash pop

  • To check the status of the current working branch:
  • git status

  • To list all local and remote branches:
  • git branch -a

  • To integrate changes of one branch into another:
  • git merge <another_branch_name>