Skip to content

Instantly share code, notes, and snippets.

@ViktorAndonov
Last active November 1, 2018 19:47
Show Gist options
  • Save ViktorAndonov/56ec0f81001c77d0867f to your computer and use it in GitHub Desktop.
Save ViktorAndonov/56ec0f81001c77d0867f to your computer and use it in GitHub Desktop.
GitHub Cheat Sheet

Usefull Git commands

This document is a cheet sheet for Git & GitHub commands that i find it usefull


Git

Commands

  • git init = when starting a new project, use this to initialize git in there;
  • git status = shows what needed to be commited, witch branch you on etc;
  • git add . = add everything to stage, ready for commit, (.) everything;
  • git commit -a -m = -a for all changes, -m for quick message;

GitHub

Description

  • gh-pages = this is not command, its a branch name to use github pages - it must me named like this to work.

Git Branches

Commands

  • git branch = use it to show the available branches, and witch one you using it;
  • git checkout [branch name] = switch between branches or create new one if the name does not exist;
  • git checkout -b [branch name] = create new branch and switch to it;
  • git branch -d [branch name] = to delete branch (wont allow if is no merged);
  • git branch -D [branch name] = force delete a branch (even if is not merged);
  • git checkout --theirs -- [path name] = when you have conflict of blob, and want to select the other branch instead of the master, --theirs used to say the other branch, and add the path name, the add it to stage + commit

Git Merging

Commands

  • git merge = you need to be in the dir that you want to recive the files;
  • git branch --merged = show what branches have been merged;
  • git branch --no-merged = shows witch branches has not been merged;

Git Cherry Pick Commits

Commands

  • git status = no changes in both branches that;
  • git checkout = the branch that you want to pick from it;
  • git log = find the commit full number and copy it;
  • git checkout = the branch that you want to recive the picked commit;
  • git cherry-pick = you are done, if you get conflicts resolve them manualy;

Git Cleaning Up

Commands

  • git checkout -- . = discard(delete) all uncommited changes in current branch;
  • git branch -m [new-name] = rename the current branch;
  • git branch -m [old-name] [new-name] = rename some other branch;

Git Shortcuts (custom zshel)

Commands

  • gs = shortcut for git status (custom zshel)
  • gl = shortcut for git log (custom zshel)
  • gaa = shortcut for git add . (custom zshel)
  • gc = shortcut for git commit -a -m (custom zshel)
  • gcm = shortcut for git checkout master (custom zshel)

p.s: with = starts the comment about the command, dont write that part = ...;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment