Beginner Git Commands

git add -A

Add all new and changed files to the staging area

git add <pathname>

Stage changes for the next commit

git branch

List all branches

git branch -d <branchname>

Delete a branch

git branch -M <branchname>

Forcefully rename the current branch to <branchname>

git branch -m <old_branchname> <new_branchname>

Rename a branch

git branch -v

List all branches including commit information

git branch <branchname>

Copy current branch as a new branch

git checkout -b <branchname>

Create a new branch and switch to it

git checkout -b <branchname1> <remote>/<branchname2>

Clone a remote branch and switch to it

git checkout <branchname>

Switch to a different branch

git clone <repo_url>

Clone a remote Git repository

git commit -a

Commits any changes to tracked files in the current repository.

git commit -m <message>

Commit staged changes with a message

git config pull.rebase false

Configure git to always merge the changes when doing a pull

git diff --staged

Displays changes between the index and the last commit.

git diff <commitA> --name-only

Show the names of the changed files between the current commit and specific commit

git diff HEAD

Show uncommitted changes

git fetch

Download remote changes

git init

Initialize a Git repository in the current directory

git log

Show the commit history

git log -<number>

Display the last <number> commits in the repository

git merge <branchname>

Merge a branch into the current branch

git pull

Fetch and merge remote changes

git pull <remote>

Fetches and merges remote changes into the current branch

git push

Uploads local repository content to a remote repository

git reflog

Show a log of all Git references

git restore --staged

Move all files from the staging area back to the working directory

git restore --staged <pathname>

Unstages the specified file/s

git restore .

Reverts all uncommitted changes in the current directory.

git rm --cached <pathname>

Remove files only from the git index

git rm -f <pathname>

Forcefully removes a file from the working directory and stages the deletion.

git rm <pathname>

Remove a file or a directory from the file system and from git's index

git status

Show the status of the current repository

git status -s

Display a short summary of the working directory's status

Navigate with the arrow keys or swipe on mobile