Git Commands

Git Installation Steps


  • Download Git for Windows from
  • Run the downloaded installer file and follow the installation instructions. Default settings are usually fine.
  • Once installed, open Command Prompt or Git Bash and verify the installation by running: git --version


  • Git should already be installed on macOS. Open Terminal and verify by running: git --version
  • If Git is not installed, you can install it using Homebrew by running: brew install git

Git Commands

git init

Initialize a new Git repository in the current directory.

git clone

Clone an existing repository from a URL.

git add  

Add a file to the staging area.

git add .

Add all files in the current directory to the staging area.

git commit -m 'commit message'

Commit staged changes to the repository with a descriptive message.

git status

Show the current state of the repository, including tracked/untracked files and changes not staged for commit.

git log

Display commit history.

git branch

List all branches in the repository.

git branch

Create a new branch.

git checkout

Switch to a different branch.

git checkout -b

Create a new branch and switch to it.

git merge

Merge changes from the specified branch into the current branch.

git push

Push commits from the local repository to a remote repository.

git pull

Fetch changes from a remote repository and merge them into the current branch.

git remote -v

List all remotes associated with the repository and their URLs.

git remote add

Add a new remote repository.

git remote remove

Remove a remote repository.

git reset

Unstage changes for a specific file.

git reset --hard

Discard all local changes and revert to the last commit.

git stash

Temporarily shelve changes that are not ready to be committed.

git tag

Create a lightweight tag for the current commit.

git tag -a -m 'tag message'

Create an annotated tag with a message.

git fetch

Fetch changes from a remote repository without merging.

git --help

Display help information about Git and its commands.