Skip to content

Instantly share code, notes, and snippets.

@TheAkashicTraveller
Forked from Kibur/git-commands
Last active August 20, 2016 20:34
Show Gist options
  • Save TheAkashicTraveller/087e4bbe1b71990b67c09f5c4d25a8b7 to your computer and use it in GitHub Desktop.
Save TheAkashicTraveller/087e4bbe1b71990b67c09f5c4d25a8b7 to your computer and use it in GitHub Desktop.
Using Git bash
Git commands
==============
[] <= optional
Cloning
---------
git clone <url.git> [path/to]
git clone -b <branch> --single-branch <url.git> [path/to]
Staging
---------
Stage (added/modified files):
git add . <= add every changes, ignored files EXCLUDED
git add . [-f] <= add every changes, ignored files INCLUDED
git add <file> <= selective adding changes
git add <file> [-f] <= selective adding ignored files
Stage (removed files):
git rm <file> <= remove files
git rm <file> [-r] <= remove directories
Recover or undo changes (unstage first):
git checkout -- <file>
Unstage
---------
git reset HEAD <= unstage everything
git reset HEAD [file] <= selective unstage
Commiting
---------
git commit
Edit commit (add files or change message)
---------
git add ...
git commit --amend
Un-commit
---------
git reset HEAD~
Push
---------
git push
Revert push
---------
git revert <commit hash>
Change branch
---------
git checkout <branch>
Create branch
---------
Local:
git branch <name>
Alternative:
git checkout -b <name>
Online:
git push -u origin <name>
Delete branch
---------
Local:
git branch -d <branch>
Online:
git push origin --delete <branch>
Merge
---------
Merge <branch> into current branch
git merge <branch>
Stash
---------
git stash <= add current changes into stash
git stash list <= shows all stashes
git stash apply <= work on the last stash of the list
git stash apply [stash@{x}] <= select the stash to work on
git stash drop <stash@{x}> <= remove stash from list
git stash pop <stash@{x}> <= combination "apply" and "drop"
Fetch
---------
git fetch
Pull
---------
git pull
Git status !!!
---------
git status
Repository log
---------
git log
Conflicts (informative)
---------
Everything between "<<<<<<<HEAD" and "=======" are local changes (current changes).
And everything between "=======" and ">>>>>>>>" are changes that failed to merge (online).
git show <commit hash> <= shows what changes were made in a given commit
git diff <= current changes
git mergetool <= fix a conflict (with system's default graphical diff tool)
git config --global merge.tool vimdiff <= sets a default merge tool
Change committer information
---------
--global <= ~/.gitconfig
--local (default) <= rep/.git/config
git config [--global] user.name "Your Name"
git config [--global] user.email you@example.com
See all configs
---------
git config --list
Configuring a remote for a fork
---------
git remote -v <= list current configured remote repository
git remote add upstream <original_url.git>
Syncing a fork
---------
git fetch upstream
git merge upstream/<branch>
Rebase (Can be used to clean up superfluous commits)
---------
git rebase upstream/<branch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment