Back
Jul 20, 2024 · 6 min read

Git Command Datasheet

Quick reference for the most-used Git commands: setup, branches, commits, syncing and undoing changes.

GitCLIReferencia

Quick reference for the most-used Git commands day to day: setup, branches, commits, syncing with the remote, and undoing changes.

01 · Configuration

CommandDescription
git config --global user.name "Your Name"Sets your username.
git config --global user.email "youremail@example.com"Sets your email address.

02 · Initialization

CommandDescription
git initInitializes a new repository.
git clone REPOSITORY-URLClones an existing repository.

03 · Repository status

CommandDescription
git statusShows the repository's status.

04 · Tracking changes

CommandDescription
git add file-nameAdds a specific file to the staging area.
git add .Adds all changes to the staging area.
git reset file-nameRemoves a file from the staging area.

05 · Branches

CommandDescription
git branch -aLists all branches.
git branch -m branch-nameCreates or renames a branch.
git branch -d branch-nameDeletes a branch.
git checkout branch-nameSwitches to an existing branch.
git checkout -b new-branch-nameCreates and switches to a new branch.
git diff branch1 branch2Compares two branches.

06 · Change history

CommandDescription
git logShows all commits with their IDs.
git checkout commit-idSwitches to a specific commit.
git diff commit-id-1 commit-id-2Compares two commits.

07 · Commits

CommandDescription
git commit -m "your message"Records changes with a message.
git pushPushes changes to the remote repo (current branch).
git push origin branch-namePushes changes to a specific remote branch.

08 · Syncing

CommandDescription
git pullFetches and merges changes from the remote.
git fetchShows differences between local and remote.

09 · Undoing changes

CommandDescription
git checkout -- file-nameDiscards changes in a modified file.
git reset --soft HEAD~1Undoes a commit, keeping the changes.
git reset --hard HEAD~1Undoes a commit and discards the changes. (Caution)

10 · Other actions

CommandDescription
git diffShows uncommitted changes.
git log file-nameShows the history of a specific file.
git tag tag-nameTags a commit.

Additional notes

Caution: some commands can cause data loss, such as git reset --hard.

Help: use git help command-name for more information about each command.

Back