Skip to content

Instantly share code, notes, and snippets.

@magicpotion
Last active January 4, 2021 17:21
Show Gist options
  • Save magicpotion/f9e5b35397e1ce9681d484691e92fca1 to your computer and use it in GitHub Desktop.
Save magicpotion/f9e5b35397e1ce9681d484691e92fca1 to your computer and use it in GitHub Desktop.
git hints

-------CONFIG-----------

git config --list --show-origin

-------BRANCHES---------

git push -u origin {name}
git checkout --track origin/{branch}

git branch -d {name}        ## delete local branch  
git branch -r               ## list remote branches  
git branch -avv             ## list branches detailed  
git remote prune origin     ## delete leftover local branches

MERGING Remote Master to Local

git fetch origin  
git merge origin/master (git pull)  
git rebase origin/master (git pull --rebase)  
(error)  git add {file} for each conflict; git rebase --continue  

Fetch recent submodules

git submodule update --init --recursive  

git stashing (with untracked files)

git stash -u  
git pull origin master  
git stash pop  

updating one file from remote repo

git fetch  
git checkout origin/master -- path/to/file  

OTHER COMMANDS

git checkout ## revert file to previous commit

git cherry-pick -x ## do in branch you want to merge pick
git cherry-pick -n 5ed3408a^..cbdf7ea2 ## merge range of commits, unstagged

  1. git reset --soft HEAD^
  2. git reset --hard HEAD^ Undo last commit and all changes $
  3. git status -v
  4. git log / git show
  5. git config --global alias.st status
  6. git diff --cached -- see uncommited changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment