Git Commands

Add Remote

git remote add <remote> <url_to_remote>

Adds a new remote to the repository

Check Git Version

git --version

Displays the currently installed Git version

Check Status

git status

Displays current changes and staged files

Clone Repository

git clone <remote_repo_url>

Clones a remote repository to local

Clone Specific Branch

git clone -branch <branch_name> <repo_url>

Clones a specific branch from a repository

Commit Changes

git commit -m “[Commit message]”

Commits staged changes with a message

Create New Branch

git branch <new_branch>

Creates a new local branch

Fetch Changes

git fetch <remote>

Downloads new data from the remote repository

Initialize Repository

git init

Initializes a new Git repository

List Branches

git branch --list

Lists all local branches

List Remotes

git remote

Lists all remotes connected to the repository

Pull Changes

git pull <remote>

Pulls and merges changes from the remote repository

Push Changes

git push

Pushes committed changes to the remote repository

Set Git Email

git config user.email [your.email@domain.com]

Sets the user email for commits

Set Git Username

git config user.name [your-name]

Sets the username for commits

Stage All Changes

git add .

Stages all changes in the current directory

Stage File or Directory

git add <filename_or_dir>

Stages specific files or directories for commit

Stash Changes

git stash

Temporarily saves changes not yet committed

Switch Branch

git checkout <branch>

Switches to a different branch