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

?git Cheat Sheet

Git is a version control system used to track changes to code. This cheat sheet provides commands for configuring Git, starting and cloning projects, committing changes, branching code, tagging versions, and synchronizing repositories. Key commands include git init to start a project, git add and git commit to save changes locally, and git push to share changes remotely.

Uploaded by

Raj Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

?git Cheat Sheet

Git is a version control system used to track changes to code. This cheat sheet provides commands for configuring Git, starting and cloning projects, committing changes, branching code, tagging versions, and synchronizing repositories. Key commands include git init to start a project, git add and git commit to save changes locally, and git push to share changes remotely.

Uploaded by

Raj Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Git Cheat Sheet 1

01 Git configuration
git config --global git rm [file] Remove file from working directory and staging area.
Set the name that will be attached to your commits and tags.
user.name “Your Name”

git config --global


Set the e-mail address that will be attached to your commits
user.email “you@example.
com”
and tags. 04 Storing your work
git config --global Put current changes in your working directory into stash for
Enable some colorization of Git output. git stash
color.ui auto later use.

Apply stored stash content into working directory, and clear


git stash pop
stash.

02 Starting a project git stash drop Delete a specific stash from all your previous stashes.

Create a new local repository in the current directory. If


git init [project name] [project name] is provided, Git will create a new directory
named [project name] and will initialize a repository inside it. 05 Git branching model
List all local branches in repository. With -a: show all branches
Downloads a project with the entire history from the remote git branch [-a]
git clone <project url> (with remote).
repository.

git branch [branch_name] Create new branch, referencing the current HEAD.

03 Day-to-day work git rebase [branch_name]


Apply commits of the current working branch and apply them
to the HEAD of [branch] to make the history of your branch
more linear.
Displays the status of your working directory. Options include
git status new, staged, and modified files. It will retrieve branch name, git checkout [-b] Switch working directory to the specified branch. With -b: Git
current commit identifier, and changes pending commit. [branch_name] will create the specified branch if it does not exist.

Join specified [branch_name] branch into your current branch


Add a file to the staging area. Use. in place of the full file path git merge [branch_name]
(the one you are on currently).
git add [file] to add all changed files from the current directory down into
the directory tree.
git branch -d [branch_ Remove selected branch, if it is already merged into any other.
name] -D instead of -d forces deletion.
git diff [file] Show changes between working directory and staging area.

Shows any changes between the staging area and the


git diff --staged [file]
repository.

Discard changes in working directory. This operation is Commit a state of the code base
git checkout -- [file]
unrecoverable.
Branch a reference to a commit; can have a tracked upstream
Revert some paths in the index (or the whole index) to their Tag a reference (standard) or an object (annotated)
git reset [<path>...]
state in HEAD.
HEAD a place where your working directory is now
Create a new commit from changes added to the staging area.
git commit
The commit must have a message!
2

06 Inspect history 09 Synchronizing repositories


List commit history of current branch. -n count limits list to last Fetch changes from the remote, but not update tracking
git log [-n count] git fetch [remote]
n commits. branches.

git log --oneline An overview with reference labels and history graph. One git fetch --prune Delete remote Refs that were removed from the remote
--graph --decorate commit per line. [remote] repository.

List commits that are present on the current branch and not Fetch changes from the remote and merge current branch with
git log ref.. git pull [remote]
merged into ref. A ref can be a branch name or a tag name. its upstream.

List commit that are present on ref and not merged into current git push [--tags]
git log ..ref Push local changes to the remote. Use --tags to push tags.
branch. [remote]

List operations (e.g. checkouts or commits) made on local git push -u [remote] Push local branch to remote repository. Set its copy as an
git reflog
repository. [branch] upstream.

07 Tagging commits 10 Git installation


git tag List all tags. For GNU/Linux distributions, Git should be available in the standard system repository. For
example, in Debian/Ubuntu please type inthe terminal:
git tag [name] Create a tag reference named name for current commit. Add
[commit sha] commit sha to tag a specific commit instead of current one. sudo apt-get install git

If you need to install Git from source, you can get it from git-scm.com/downloads.
git tag -a [name]
Create a tag object named name for current commit.
[commit sha] An excellent Git course can be found in the great Pro Git book by Scott Chacon and Ben Straub.
The book is available online for free at git-scm.com/book.

git tag -d [name] Remove a tag from local repository.

11 Ignoring files
08 Reverting changes cat <<EOF > .gitignore

/logs/*

Switches the current branch to the target reference, leaving


!logs/.gitkeep
git reset [--hard] a difference as an uncommitted change. When --hard is used,
[target reference] all changes are discarded. It's easy to lose uncommitted
/tmp
changes with --hard.
*.swp

Create a new commit, reverting changes from the specified


git revert [commit sha] EOF
commit. It generates an inversion of changes.

To ignore files, create a .gitignore file in your repository with a line for each pattern. File ignoring will
work for the current and sub directories where .gitignore file is placed. In this example, all files are
ignored in the logs directory (excluding the .gitkeep file), whole tmp directory and all files *.swp.

You might also like