Skip to content

Instantly share code, notes, and snippets.

@artivilla
Last active April 5, 2017 02:56
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 artivilla/e1499875567998269bf66f2cb6534c96 to your computer and use it in GitHub Desktop.
Save artivilla/e1499875567998269bf66f2cb6534c96 to your computer and use it in GitHub Desktop.
git
Refs: https://gist.github.com/hofmannsven/6814451
Remotes
Show tracked / untracked info for local branches
$git remote -vv
Clean up traked info for remote branches
$git remote prune <remote>
To update your local branch with remote
$git reset --hard <long commit number>
Cherry pick (a range of commits form one branch into another)
$git cherry-pick A..B (commit A needs to be older than B, excludes A, wrong order will fail silently, A^..B to include A)
Pull files from another branch
Ref: http://stackoverflow.com/questions/307579/how-do-i-copy-a-version-of-a-single-file-from-one-git-branch-to-another
$git checkout otherbranch myfile.txt
Formulaes:
$git checkout <commit_hash> <relative_path_to_file_or_dir>
$git checkout <remote_name>/<branch_name> <file_or_dir>
Delete untracked files
$git clean -f
$git clean -df (for folders)
Untrack files already commited in the codebase remotely you don't want to change / not show up in gitdiff
$git update-index --no-assume-unchanged <filename>
$git update-index --assume-unchanged <filename> //to undo
(Add to .gitignore if it hasn't been already commited)
See differences in commits between two branches (+ represents commits that havne't been commited into next)
$git checkout <branch>
$git cherry -v <nextbranch>
Tracking Remotes
See which remotes you're tracking
$git remote --v
Track a remote branch from current local branch
$git branch --track <remotebranch>
Force push only if noone else has pushed to a shared/remote branch
$git push --force-with-lease
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment