Git Version Control
When a # is used, this indicates a comment
When a <> is used, this indicates the location for a file, tag, hash, etc.
git commit -a -m 'added new benchmarks' # Adds all changes and commits in one line
git config --global user.name "David Yakobovitch" # Set a name for commits
git config user.name # View what is username, and same option for other config parameters
git config --global user.email "[email protected]" # Set an e-mail for commits
git config --global core.askpass # If wrong password typed, remind Github/Bitbucket/Gitlab to ask for password
git config --global core.autocrlf input # Disable CR LF message
git config --global core.autocrlf false # Disable CR LF message
git config --global core.editor "code" # Set your preferred text editor with Git
git config --list # View configuration settings
git config --help # View help for configuration options
git config --global rerere.enabled true # Avoid Repeated Merge conflicts
git config --global http.proxy http://user:[email protected] # Configure proxy credentials
git config --global https.proxy http://user:[email protected]
git config --global alias.co checkout # create git alias for commands git co would now work
git config --global alias.unstage 'reset HEAD--' # creates unstage command, I.e., (git unstage fileA)
git clone [_url_here] [directory_name_here] [local_file_path_here]
git clone <dir> <new_dir_name> # Creates a clone of directory as new repository locally
git clone -o hello_world # Default remote branch named as hello_world/master
git pull # Equivalent to git fetch, and then auto git merge origin/master
git remote -v # View the remote repository location
git remote # View the remote repository name
git remote show <repo_name> # Shows info about the remote repository
git remote show origin
git remote add <shortname> <url> # Adds the repo as a remote to original repo
git remote add origin url #becomes master
git remote rename pb paul # Rename remote repository shortnames
git remote remove paul # Removes a remote repository connection
git ls-remote
git init [directory_name]
git init # inside the directory
mkdir [directory_name] #create directories
touch [file_name.extension] #create empty files
echo "text goes here" > file.txt #creates new file with text values
git add . # all changes to be logged
git add [file.txt] # logs a file change
git add [file-1.text] [file-2.txt] # logs file changes for specific files
git add -h # View all flag options with add command
git commit -m "message goes here"
git commit --message "message goes here"
git commit --author="Vlad Dracula <[email protected]>" # chan
git commit --amend -m "comment" #Amends most recent commit for small update, shorter than a reset w/ commit
git commit -a -m 'added new benchmarks' # Adds all changes and commits in one line
git commit --author="David Yakobovitch <[email protected]>" # Change author for a specific commit message
git commit --amend # start $EDITOR to edit/amend the message
git status
git status --short # See abbreviated changes
git status -s # See abbreviated changes
git diff # Shows changed before git add
git diff --staged # Shows changed after git add before git commit
git diff --cached # Same as git diff --staged
git diff HEAD <hash> <file_name> # Show the most recent changes for file on a Hash commit
git diff HEAD~1 <file_name> # Shows changes to file one previous version
git diff master..<branch_name> #Display differences between branches
git diff format-patch master..<branch_name> # Generates a file with patch for each commit reachable in the branch but not from the master
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='15 minutes ago'
git log --pretty=oneline --since='2.weeks'
git log --pretty=oneline --since='2008-01-15'
git log --pretty=oneline --since='2 years 1 day 3 minutes ago'
git log --pretty=oneline --until='15 minutes ago'
git log --pretty=oneline --all
git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'
git log --patch cats.txt # Shows log and diff together # Could use -p as alternative
git log -2 # Shows 2 most recent commits
[text_editor_name] .gitignore
nano .gitgnore
*.a # Do ignore all files with this extension
.[oa] # Ignore files ending in .o or .a
*~ # Ignore all files ending in tilda ~
/TODO # only ignore the TODO file in the current directory, not subdir/TODO
!lib.a # Do not ignore this file
doc/*.txt # Ignore only files in doc directory ending in extension
doc/**/*.pdf # Ignore all files in doc directory and sub-directories ending in extension
build/ # Ignore all files in directory named build
/heart # Ignore the heart file in current directory
echo filename >> .gitingore # add it to .gitignore to avoid re-adding it
git tag -l # View the tag history as a list
git tag -l "v1.8.5*" # View tags in 1.8.5 series
git tag v1 # Adds a tag to a commit
git tag <tag_name> <hash> # Adds a tag to a commit named with its hash
git tag -d tagname # Deletes the tag name
git tag -a v1.4 -m "my version 1.4" # Creates annotated tag with a message
git show v1.4 # Shows the info about the tag and commit attached, no other info
git tag -a v1.2 <hashid> # Attached a tag to a hashid
git tag -d <tagname> # Deletes a tag
git push origin --delete <tagname> # Delete a tag from remote
git checkout v1 # Checkout the branch to a specific commit with tag
git checkout v2~1 # Checkouts 1 previous version with tag
git checkout v2^1 # Checkouts 1 previous version with tag
git checkout <file_name> #Checkouts a specific filename # Removes local version
git checkout . # Reset all uncomitted code
git checkout HEAD~1 # Roll back one version
git checkout <hash> <file_name> # Roll back one version for a file
git checkout -f master <file_name> # Checks out one previous commit for file from Github/Bitbucket/Gitlab
git checkout master
git rm <filename> # Stages or adds the file for removal before commit
git rm --cached <filename> # Keep file in working tree, but remove from staging
git reset HEAD <filename> # Undoes changes to the file from recent commit, but is available to recommit
git reset --hard <tag or hash> # Undoes commit back to the previous version
git fetch <shortname> # Downloads data from remote repo, but does not merge
git reset HEAD <file_name> # Removes staged files
git reset HEAD~2 # Undoes last two commits, keep changes
git reset --hard HEAD~2 # Undoes last two commits, discard changes
git reset <file_name> # Removes file; same operation as git remove --cached <file_name>
git reset --soft HEAD~1 # Soft reset against messy code, but still exists so you can fix and re-commit
git reset --hard HEAD~1 # Permanently erases previous commit
git revert HEAD #Reverts changes after committing if accidently committed
git revert c761f5c # reverts the commit with the specified id
git revert HEAD^ # reverts the second to last commit
git revert develop~4..develop~2 # reverts a whole range of commits
git revert -n HEAD # undo the last commit, but don't create a revert commit
# First, be sure to set in ~/.gitconfig an [alias] for hist
# [alias]
# hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
git hist master --all # Show all commit history
git hist --all # Show all history, even when a hard reset is performed, as all history is preserved
git hist --stat # Shows changes per each file as well
# Note: HEAD is the currently checked out commit.
git show # Displays the most recent commit on the HEAD
git show HEAD~2 mars.txt # View version to roll back
git show HEAD^ or git show HEAD^1 or git show HEAD~ # View the parent of the HEAD commit
git show HEAD^^ # View the grandparent or second parent of the HEAD commit
git show <tag or hash>:<file_name> # View old version of the file
git rev-list master..<your_branch> | wc -l # View how many commits ahead your branch is over the master/origin
git cat-file -p <commit-ID> #can be run on the tree (points to blobs), blob (sub-directory of files) or commit (points to tree)
source ~./profile
source ~/.gitconfig
cat .git/objects/ce/<commit> | inflate | wc -c # Display wordcoutn of an object (requirs ruby installation)
cat .git/objects/ce/<commit> | inflate | hexdump -C # Explore hex characters
gitk # Visual interactive of all commits in a git repository
git push <remote> <branch> # Push upstream to remote from a branch your updates
git push origin master # Pushes the updates to the master branch
git push -u origin master
git push --force # forces a push, could have issues with conflicts
git push shared master # Push changes to a remote shared repository
git push origin <tagname> # Pushes the tag to remote server, otherwise is only local
git push origin --tags # Transfer all local tags to remote server not already there
git push origin --delete <remote> # Deletes remote branch from main remote
git merge feature # The feature branch merges into your active branch
git merge master feature
git merge-base feature master
git merge origin/master # Can locally merge changes after a git fetch if desired
git mergetool # Launches your default merge tool to handle merges
git branch <branch_name> # Creates a new branch
git checkout -b <branch_name> # Creates a new branch and switches to the branch
git checkout <remote_branch> # Creates and tracks branch if only 1 version on remote available
git checkout -b sn origin/branch # Creates branch with short alias name sn
git branch # View all local current branches
git branch -a # View all branches
git branch -d <branch_name> # Deletes a branch
git branch --track <branch_name> origin/<branch_name> # Add a local branch that tracks a remote branch
git branch -r # Examine branches being tracked from remote repositories
git branch -v # View the last commit on each branch
git branch -vv # Shows which local branches being tracked
git fetch --all; git branch -vv # For up-to-date tracking data
git branch --merged # View which branches already merged into currently pointed branch
git branch --no-merged # Show branches not yet merged
git fetch # Retrieves updates from remote repo but does not merge them
git clone --bare hello hello.git # Used for sharing commits without files
git rebase -i master
git rebase -i HEAD~2 # be presented with last 3 commits --root # for local
git rebase --onto HEAD [commitID] master
git rebase --continue
git rebase --skip
git rebase --interactive
git rebase --interactive origin branch
git rebase --abort #cancels the rebase
git stash # code available for later
git stash list # see the changes
git stash apply #applies stash
git stash apply stash@{1}
git stash branch 'debugging-branch' # saves stashes in new branch
git stash drop stash@{2} #drops one stash at a time
git stash clear # removes all stashes
git bisect start #launches git bisect utility
git bisect bad [commitID] #indicate where a problem exists
git bisect good [commitID] #git searches for where issue occured and resolves
git bisect bad [no commit ID needed] # if still bad
git bisect good #once it's good
git bisect reset #reset branch to normal working state after
pick [commitID] # a screen will appear and you can change all before pick to say squash to merge them
squash [commitID] # squash specific id into the pick
git checkout -- Gemfile # reset specified path
ctrl + shift + c #gitbash copy for PC
ctrl + v #pastes for gitbash
unset SSH_ASKPASS #asks for password
alias gaa='git add .'
alias gc='git commit'
alias ga='git add'
alias gaaa='git add --all'
alias gau='git add --update'
alias gb='git branch'
alias gbd='git branch --delete '
alias gcm='git commit --message'
alias gcf='git commit --fixup'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gcos='git checkout staging'
alias gcod='git checkout develop'
alias gd='git diff'
alias gda='git diff HEAD'
alias gi='git init'
alias glg='git log --graph --oneline --decorate --all'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias gm='git merge --no-ff'
alias gma='git merge --abort'
alias gmc='git merge --continue'
alias gp='git pull'
alias gpr='git pull --rebase'
alias gr='git rebase'
alias gs='git status'
alias gss='git status --short'
alias gst='git stash'
alias gsta='git stash apply'
alias gstd='git stash drop'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gsts='git stash save'
- Software Carpentry Git Lesson
- The Simple Git Guide
- Atlassian Version Control
- Git Manual Online
- Git User Manual
- Blog: The Thing About Git
- Pro Git Book
- Github.com Help
- Think Like a Git
- Fork - Merge Visualizer for Windows/Mac
- Git Immersion
- Toptal Best Practices
- Git Workflows
- Advanced Git Commands
- Set up Tree on Windows
- Rename Windows Computer in Git Bash
- Customize Gitbash Display Windows
- Change Default Git location for Jupyter and Git Bash Windows
- Set Conda Commands from Git bash Windows 10
- Reset HTTPS Proxy Git Bash
- Change SSH to HTTPS Git
- Customize Alias on Mac for Git
- Create Additional Git Aliases
- Set Aliases Git Bash Windows