Skip to content

Instantly share code, notes, and snippets.

@n8kowald
Forked from maciakl/gist:1584387
Last active January 31, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n8kowald/2634304 to your computer and use it in GitHub Desktop.
Save n8kowald/2634304 to your computer and use it in GitHub Desktop.
Git Workflow
# GIT WORKFLOW
# (c) Luke Maciak
# Initialize:
git init
# Check Out:
git clone username@host:/path/to/repository
# Add Origin:
git remote add origin <server>
# Commit:
git add file.ext # add a single file
git add . # add everything
git commit -m "Commit Message" # commit with message
git commit -a # add all, write long msg
# Stashing (when you made changes and forgot to pull for example):
git stash # saves current state for later use
git stash apply # restores/merges stashed state
# Remove / Stop tracking a file:
git rm --cached <filename>
# Push (upload changes to remote repository):
git push origin master
# Pull (update from remote repository):
git pull origin master # for master branch
git pull origin branchname # for specific branch
# If you want to be able to just do git push, git pull:
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
# Drop all local changes and commits:
git fetch origin
git reset --hard origin/master
git checkout -- <file> # drops only changes for <file>
#Branching:
git checkout -b branchname # create new branch
git checkout master # switch back to master
git branch -d branchname # delete branch locally
git push origin :some_branch # delete branch from repository
git push origin branchname # push branch
git merge branchname # merge branchname into current (switch to master before merging)
git branch -r # view all branches existing in repository
# Tagging:
git tag -a 1.1 -m "tag description" # regular tag
git tag 1.1 # lightweight tag
git tag 1.1 9fceb02 # tag specific commit
git push --tags # push tags
git tag -d 1.0 # delete local tag
git push origin :refs/tags/1.0 # delete tag from remote
# Adding a Submodule
git submodule add usename@host:/path/to/repo foldername
# Initializing submodule in a cloned project
git submodule init
git submodule update
# Rebasing
git rebase -i HEAD~3 # rebase last 3 commits
# Patching
# Patch from a specific commit
git format-patch -1 <sha>
git apply <patchfile>
# Ignoring
git config --global core.excludesfile ~/.gitignore_global # set up a global ignore file
cache/* # ignore all files inside the cache folder, keep the folder
cache* # ignore all files including the cache folder
!.gitignore # lines starting with ! are exceptions
# Gitdiff shortcuts
Next line: return
Next page: space bar
Previous page: w
Quit viewing the diff: q
Help: h
# Home .gitconfig Settings
[credential]
helper = cache --timeout=3600
[color]
status = auto
diff = auto
branch = auto
interactive = auto
ui = true
[alias]
st = status -s -b
ci = commit
di = diff
br = branch
co = checkout
l = log --oneline --decorate --graph
timeline = log --graph --branches --pretty=oneline --decorate
untracked-files = ls-files --o --exclude-standard
ignored-files = ls-files --others -i --exclude-standard
modified-files = ls-files -m
# Links to Git References
http://help.github.com/git-cheat-sheets/ #Official git cheatsheet
http://daringfireball.net/projects/markdown/syntax #Markdown Syntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment