Intermediate Git Commands

git add .

Stage all changes in the current directory

git blame <pathname>

identify changes in a file by author and time.

git branch -D <branchname>

Delete a branch forcefully

git branch -r

List remote branches

git branch -vv

List all branches with extra verbose information

git checkout -

Switch to the branch last checked out

git checkout --<pathname>

Discard changes in working directory.

git checkout HEAD <pathname>

Restore a file from the most recent commit

git cherry-pick <commitA>

Apply the changes introduced by <commitA> on top of the current branch.

git clone <repo_url> <local_repo_name>

Creates a copy of a remote repository with a different name on your local machine

git commit --amend -m <message>

Change the commit message in the last commit

git diff --stat

View a summary of changes between your working directory and the staging area

git diff <branchname1>..<branchname2>

Show the difference between the contents of two branches

git diff HEAD --stat

View a summary of changes from the last commit

git diff HEAD HEAD^

Displays the differences between the two most recent commits.

git diff HEAD~ HEAD

Shows changes between the last and current commit.

git log --all -- <filepath>

List complete commit history involving a specific file.

git log --all --grep=<searchterm>

Search commit messages in all branches

git log --oneline

View git commit history summarized

git log --oneline --graph

Displays condensed repository history in a graphical format.

git log ..<branchname>

Lists the commits that are available in <branchname> but not in the current branch

git prune

Removes unreachable objects

git push <remote> <branchname>

Upload local changes to a remote repository

git push origin -d <branchname>

Delete a remote branch

git rebase <branchname>

reapply commits from the current branch onto <branchname>

git remote add origin <repo_url>

Links a local repository to a remote one.

git reset -- <pathname>

Unstage changes to a specific file or files

git reset <commit>

Reset the repository or a file to a specific commit

git reset HEAD <pathname>

Unstage changes for a specific file or files

git revert <commit>

Revert the changes introduced by a specific commit

git show <commit>

Displays content changes of a specific commit

git stash

Temporarily saves changes that are not ready to be committed.

git stash pop

Restores the most recently stashed changes and deletes the stash

git stash push -m <message>

Stashes the changes in the working directory with a custom message.

git stash save <message>

Stash changes with a custom message

Navigate with the arrow keys or swipe on mobile