Git. Most used commands

Most used git commands.

Create Git repository
git init

Set remote Git repository
git remote add repoName remoteRepositoryUrl
remoteRepositoryUrl example -

Show remote Git repositories
git remote -v

Remove remote Git repository
git remote rm repoName

Stage changes
git add -A - stage everything in the working directory
git add - stage a file

git status

Show unstaged differences
git diff

Discard unstaged changes
git checkout -- . - discard all unstaged changes in the working directory
git checkout - discard unstaged changes in

Commit staged changes
git commit -m "Message"

Undo the last commit
git reset --soft HEAD^

Show branches
git branch

Switch to branch
git checkout branchName

Create a branch and switch
git checkout -b newBranchName

Fetch all remotes
git fetch --all

Pull remote branch
git pull repoName branchName

Push branch to remote
git push repoName branchName

Learn more about Git on