?git Cheat Sheet
?git Cheat Sheet
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”
02 Starting a project git stash drop Delete a specific stash from all your previous stashes.
git branch [branch_name] Create new branch, referencing the current HEAD.
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
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.
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.
11 Ignoring files
08 Reverting changes cat <<EOF > .gitignore
/logs/*
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.