Skip to content

GIT

Basics

Command Description
git init initialize a new Git repository
git clone clone a remote Git repository to a local directory
git status show the current status of the repository
git add add changes to the staging area
git commit commit changes to the repository
git log show the commit history
git diff show the differences between two commits or the working directory and the staging area

Branches

Command Description
git branch list all branches in the repository
git branch <branch-name> create a new branch with the given name
git checkout <branch-name> switch to the given branch
git merge merge a branch into the current branch
git rebase rebase the current branch onto another branch

Remotes

Command Description
git remote list all remotes for the repository
git remote add add a new remote to the repository
git fetch download changes from a remote repository
git pull download and merge changes from a remote repository
git push upload changes to a remote repository

Undoing Changes

Command Description
git reset unstage changes from the staging area
git checkout discard changes in the working directory
git revert create a new commit that undoes a previous commit
git reset --hard discard all changes in the working directory and staging area

Tagging

Command Description
git tag list all tags in the repository
git tag <tag-name> create a new lightweight tag with the given name
git tag -a <tag-name> -m <message> create a new annotated tag with the given name and message
git push --tags upload all tags to a remote repository

Submodules

Command Description
git submodule add add a new submodule to the repository
git submodule update update submodules to the latest commit
git submodule foreach <command> run a command in each submodule