0% found this document useful (0 votes)
20 views

Git Cheat Sheet

This document provides summaries of common Git commands for removing and adding files, listing commit history, branching, merging, tagging commits, reverting changes, and synchronizing repositories. Key commands covered include git rm, git log, git branch, git checkout, git merge, git tag, git reset, git revert, git fetch, and git push.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Git Cheat Sheet

This document provides summaries of common Git commands for removing and adding files, listing commit history, branching, merging, tagging commits, reverting changes, and synchronizing repositories. Key commands covered include git rm, git log, git branch, git checkout, git merge, git tag, git reset, git revert, git fetch, and git push.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

$ git rm [file] 05 Review your work

Remove file from working directory and staging area.


$ git log [-n count]
$ git stash List commit history of current branch. -n count limits list to last n
Put current changes in your working directory into stash for later use. commits.

$ git stash pop $ git log --oneline --graph --decorate


Apply stored stash content into working directory, and clear stash. An overview with reference labels and history graph. One commit
per line.
$ git stash drop
$ git log ref..
Delete a specific stash from all your previous stashes.
List commits that are present on the current branch and not merged
into ref. A ref can be a branch name or a tag name.
04 Git branching model
$ git log ..ref
$ git branch [-a] List commit that are present on ref and not merged into current
List all local branches in repository. With -a: show all branches branch.
(with remote).
$ git reflog
$ git branch [branch_name] List operations (e.g. checkouts or commits) made on local repository.
Create new branch, referencing the current HEAD.

$ git checkout [-b][branch_name]


Switch working directory to the specified branch. With -b: Git will
create the specified branch if it does not exist.

$ git merge [from name]


Join specified [from name] branch into your current branch (the one
you are on currently).

$ git branch -d [name]


Remove selected branch, if it is already merged into any other.
-D instead of -d forces deletion.

GitLab | everyone can contribute about.gitlab.com


06 Tagging known commits 08 Synchronizing repositories
$ git tag $ git fetch [remote]
List all tags. Fetch changes from the remote, but not update tracking branches.

$ git tag [name] [commit sha] $ git fetch --prune [remote]


Create a tag reference named name for current commit. Add commit Delete remote Refs that were removed from the remote repository.
sha to tag a specific commit instead of current one.
$ git pull [remote]
$ git tag -a [name] [commit sha] Fetch changes from the remote and merge current branch with its
Create a tag object named name for current commit. upstream.

$ git tag -d [name] $ git push [--tags] [remote]


Remove a tag from local repository. Push local changes to the remote. Use --tags to push tags.

$ git push -u [remote] [branch]


07 Reverting changes Push local branch to remote repository. Set its copy as an upstream.
$ git reset [--hard] [target reference]
Switches the current branch to the target reference, leaving
a dierence as an uncommitted change. When --hard is used, Commit an object
all changes are discarded. Branch a reference to a commit; can have a tracked upstream
Tag a reference (standard) or an object (annotated)
$ git revert [commit sha]
Head a place where your working directory is now
Create a new commit, reverting changes from the specified commit.
It generates an inversion of changes.

GitLab | everyone can contribute about.gitlab.com

You might also like