Git Examples

git add -A

Add all new and changed files to the staging area

Sign in to enable bookmarking, reminders, progress-tracking and more...

git add <pathname>

Stage changes for the next commit

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch

List all branches

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch -d <branchname>

Delete a branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch -M <branchname>

Forcefully rename the current branch to <branchname>

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch -m <old_branchname> <new_branchname>

Rename a branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch -v

List all branches including commit information

Sign in to enable bookmarking, reminders, progress-tracking and more...

git branch <branchname>

Copy current branch as a new branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git checkout -b <branchname>

Create a new branch and switch to it

Sign in to enable bookmarking, reminders, progress-tracking and more...

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

Clone a remote branch and switch to it

Sign in to enable bookmarking, reminders, progress-tracking and more...

git checkout <branchname>

Switch to a different branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git clone <repo_url>

Clone a remote Git repository

Sign in to enable bookmarking, reminders, progress-tracking and more...

git commit -a

Commits any changes to tracked files in the current repository.

Sign in to enable bookmarking, reminders, progress-tracking and more...

git commit -m <message>

Commit staged changes with a message

Sign in to enable bookmarking, reminders, progress-tracking and more...

git config pull.rebase false

Configure git to always merge the changes when doing a pull

Sign in to enable bookmarking, reminders, progress-tracking and more...

git diff --staged

Displays changes between the index and the last commit.

Sign in to enable bookmarking, reminders, progress-tracking and more...

git diff HEAD

Show uncommitted changes

Sign in to enable bookmarking, reminders, progress-tracking and more...

git fetch

Download remote changes

Sign in to enable bookmarking, reminders, progress-tracking and more...

git init

Initialize a Git repository in the current directory

Sign in to enable bookmarking, reminders, progress-tracking and more...

git log

Show the commit history

Sign in to enable bookmarking, reminders, progress-tracking and more...

git log -<number>

Display the last <number> commits in the repository

Sign in to enable bookmarking, reminders, progress-tracking and more...

git merge <branchname>

Merge a branch into the current branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git pull

Fetch and merge remote changes

Sign in to enable bookmarking, reminders, progress-tracking and more...

git pull <remote>

Fetches and merges remote changes into the current branch

Sign in to enable bookmarking, reminders, progress-tracking and more...

git push

Uploads local repository content to a remote repository

Sign in to enable bookmarking, reminders, progress-tracking and more...

git reflog

Show a log of all Git references

Sign in to enable bookmarking, reminders, progress-tracking and more...

git restore --staged

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

Sign in to enable bookmarking, reminders, progress-tracking and more...

git restore --staged <pathname>

Unstages the specified file/s

Sign in to enable bookmarking, reminders, progress-tracking and more...

git restore .

Reverts all uncommitted changes in the current directory.

Sign in to enable bookmarking, reminders, progress-tracking and more...

git rm --cached <pathname>

Remove files only from the git index

Sign in to enable bookmarking, reminders, progress-tracking and more...

git rm -f <pathname>

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

Sign in to enable bookmarking, reminders, progress-tracking and more...

git rm <pathname>

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

Sign in to enable bookmarking, reminders, progress-tracking and more...

git status

Show the status of the current repository

Sign in to enable bookmarking, reminders, progress-tracking and more...

git status -s

Display a short summary of the working directory's status

Sign in to enable bookmarking, reminders, progress-tracking and more...