Skip to content

Instantly share code, notes, and snippets.

@overtomanu
Last active January 17, 2021 16:44
Show Gist options
  • Save overtomanu/eead58857c366b9e519967239b3243c3 to your computer and use it in GitHub Desktop.
Save overtomanu/eead58857c366b9e519967239b3243c3 to your computer and use it in GitHub Desktop.

Converted from google sheet: https://docs.google.com/spreadsheets/d/e/2PACX-1vScHSvMHYvFfRkHipFxhoiLaarEm2XYF2QSdSSbvNq-wszctrdqn2h00DGyW29fZOaOqKB95Z16YHVV/pubhtml?gid=0&single=true

Terminology Description
origin/master Points to the master branch of "origin" which is typically the remote repository
origin/HEAD Refers to the current commit of "origin" which is the remote repository
master Points to the master branch of the local repository.
HEAD~2 or HEAD~~ 2 commits older than HEAD
HEAD^2 the second parent of HEAD, if HEAD was a merge, otherwise illegal
Command Description
git clone https://github.com/overtomanu/cloneTest.git cloneTest/ create local repository from remote git url
git status Show the working tree status - view uncomitted changes
git add .gitignore Add file with code changes for staging. staged file will be picked up in next commit
git add --all Stage all changes in working tree. adds, modifies, and removes index entries to match the working tree.
git mv Move/change the name of a file/directory
git clean Remove untracked files from working tree
git reset HEAD -- Remove a file from the index
git add -u Register changes from only files that have been added to the index
git commit -m "type_message_here commit via commandline" Record file changes to the current branch
git ls-tree -r master --name-only list all current files existing in git repo master branch
git init create local repository
git remote add origin https://github.com/overtomanu/cloneTest.git cloneTest/ add remote repository for pushing/pulling changes
git remote -v show remote repositories, name and url
git log show list of commits
git log HEAD~4..HEAD show all commits which happened between HEAD and HEAD~4
git log testing..master list all commits which are in the master branch but not in the testing branch. The double dot operator allows you to select all commits which are reachable from a commit c2 but not from commit c1. The syntax for this is c1..c2. A commit A is reachable from another commit B if A is a direct or indirect parent of B.
git log master...testing show all commits in two branches which have not yet been combined. The triple dot operator allows you to select all commits which are reachable either from commit c1 or commit c2 but not from both of them.
git --no-pager log -n2 git log with no pager, show 2 latest commits
git log --grap show branch names in tree view
git log --graph --decorate --oneline branch names and a compact view
gitk show branch names in tree view in GUI
git pull origin master get/download all changes from from remote repository(origin) branch(master)
git push -u origin master send/upload all changes done in local repository to remote repository's(origin) branch(master)
git push origin --delete err01 delete branch "err01" from remote repository
git ls-remote /url/of/the/upstream/repo list of the remote HEADS and their associated branches
git rm --cached stages the removal of the file(s) from the repo but leaves the file in your working tree (leaving you with an untracked file)
git rm remove file from repo as well as from current working tree
git rm -f remove file from staging area(if staged) and from repo
git reset -- the commit parameter is optional, if you don’t specify it, it will be referring to HEAD This command resets the index entries (the ones you added to your staging area) to their state at the specified commit (or HEAD if you didn’t specify any commits). This is mixed mode. Usefull when you have committed unnecessary file and want to remove it
git reset unstage all files
git reset --soft unstage commit on Git, Using the “–soft” argument, changes are kept in your working directory and index. As a consequence, your modifications are kept, they are just not in the Git repository anymore but they are staged to be included in next commit usefull when you have commited any spelling error in commit message
git reset --hard unstage commit on Git and discard all changes be careful when using the reset hard command, you will lose all your changes when hard resetting. Typically used when some irreversible changes have been made and cannot be manually removed without completely resetting the program
git revert HEAD reverts back the changes done in last commit
git rever Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them
git revert --abort rolls the sequencer state back, so the workspace and history end up as they were before the start of git revert
git commit --amend modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit
git show show commit details
git branch list all branches, asterisk indicates the current active branch
git branch branch1 create new branch named branch1, can create new branch only after first commit in newly created git repo
git checkout branch2 Switch to the branch "branch2"
git checkout -b branch3 Create and switch to branch "branch2"
git cherry-pick <commit SHA1's> Given one or more existing commits, apply the change each one introduces, recording a new commit for each.
git merge merge the specified commit to the current active branch, can also pass branch name for
git stash -u The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy. Adding the -u option (or --include-untracked) tells git stash to also stash your untracked files
git stash list You can run git stash several times to create multiple stashes, and then use git stash list to view them.
git stash save "stash note/message" save stash with note/message
git stash pop re-apply the most recently created stash: stash@{0}
$ git stash pop stash@{2} reapply third stash
git merge --no-ff featureBranch5 --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature
git merge --squash branch9 squash commits from the "branch9" branch to a single commit and merge it into the master/current branch
git branch -d branch4 delete branch "branch4"
git rebase -i HEAD~~ Squash last 2 commits into single commit, interactively
git rebase master rebase current branch on top of master. All commits in current branch will be moved above tip(latest commit) of the master
git rebase --continue continue rebase operation after resolving merge conflict
git rebase --abort stop rebasing after encountering merge conflict
git tag list all tags
git tag -n list tags with description
git tag minorRelease1 add unannotated light weight tag
git tag -am "This is release 1" MajorRelease1 add annotated tag (tag with description)
git tag -d delete a tag
git diff Changes in the working tree not yet staged for the next commit
git diff --cached Changes between the index and your last commit; what you would be committing if you run "git commit" without "-a" option.
git diff HEAD Changes in the working tree since your last commit; what you would be committing if you run "git commit -a"
git show-ref master show the commits master branch and remote master branch is pointing to.
echo "Apple pie" | git hash-object --stdin git SHA1 hash for the text. This is the hash that git uses as key to store value as zipped object files. Object files are stored in .git/objects folder
git cat-file show contents of object with given SHA1
git directory structure explanation A .git directory has a structure similar to the following one: objects/ folder In this directory the data of your Git objects is stored – all the contents of the files you have ever checked in, your commits, trees and tag objects. objects/[0-9a-f][0-9a-f] folders A newly created object is stored in its own file. The objects are placed over 256 subdirectories using the first two characters of the SHA1 object name to keep the number of directory entries in objects itself to a manageable number. Objects found here are often called unpacked or loose objects. objects/pack folder Files that store many object in compressed form, along with index files to allow them to be randomly accessed are found in this directory. objects/info folder Additional information about the object stored is placed in this directory. refs folder References are stored in subdirectories of this directory. The git prune command knows to preserve objects reachable from refs found in this directory and its subdirectories. refs/heads/ folder Contains commit objects. refs/tags/ folder Contains any object name. refs/remotes/ folder Contains commit objects of branches copied from a remote repository. packed-refs file The file consists of packed heads and tags. It is useful for an efficient repository access. HEAD file This file holds a reference to the branch you are currently on. This tells Git what to use as the parent of your next commit config file This is the main Git configuration file. It keeps specific Git options for your project, such as your remotes, push configurations, tracking branches and more. Your configuration will be loaded first from this file, then from a ~/.gitconfig file and then from an /etc/gitconfig file, if they exist. branches A deprecated way to store shorthands to be used to specify a URL to git fetch, git pull and git push. This mechanism is legacy and not likely to be found in modern repositories. hooks folder This directory contains shell scripts that are invoked after the corresponding Git commands. For example, after you run a commit, Git will try to execute the post-commit script. index file The GIT index is used as a staging area between your working directory and your repository. You can use the index to build up a set of changes that you want to commit together. When you create a commit, what is committed is what is currently in the index, not what is in your working directory. It is a binary file containing a sorted list of path names, each with permissions and the SHA-1 of a blob object. info folder Additional information about the repository is recorded in this directory. remotes folder This folder contains shorthands for URL and default refnames for use when interacting with remote repositories via git fetch, git pull and git push commands. This mechanism is legacy and not likely to be found in modern repositories. logs folder Stores the changes made to refs in repository. logs/refs/heads/ folder Records all changes made to the different branch tips logs/refs/tags/ folder Records all changes made to the different tags modules folder Contains the git-repositories of the submodules. worktrees folder Contains administrative data for linked working trees. Each subdirectory contains the working tree-related part of a linked working tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment