Skip to content

Instantly share code, notes, and snippets.

@skarabasakis
Forked from maciakl/gist:1584387
Last active September 3, 2017 22:11
Show Gist options
  • Save skarabasakis/dd895d8cd22403dd9a1d93a02843f328 to your computer and use it in GitHub Desktop.
Save skarabasakis/dd895d8cd22403dd9a1d93a02843f328 to your computer and use it in GitHub Desktop.
Git Workflow
# GIT WORKFLOW
# 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 to staging
git add --patch file.ext # add changes from file, line by line
git add . # add everything
git reset file.ext # undo git add - unstage a file
git commit -m "Commit Message" # commit with message
git commit -a # add all, write long msg
git commit --amend # amend changes to previous commit
# 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
git stash unapply # reverts stash apply
# Remove / Stop tracking a file:
git rm --cached <filename>
# Push (upload changes to remote repository):
git push origin master
git push --set-upstream origin master # set default upstream for push
git push # once you set default
# Pull (update from remote repository):
git pull # default branch
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 commits and revert to origin:
git fetch origin
git reset --hard origin/master
# Drop all uncommited changes
git checkout -- <file> # drops only changes for <file>
git checkout -- . # drops all the changes
# Branching:
git checkout -b branchname # create new branch
git checkout master # switch back to master
git branch -d branchname # delete branch
git push origin branchname # push branch
git merge branchname # merge branchname into current
# Rebasing
git rebase -i HEAD~3 # rebase last 3 commits
# Diffs
git diff # diff against working area
git diff --staged # dif against staged (added) files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment