Skip to content

Instantly share code, notes, and snippets.

@nebtrx
Last active June 6, 2019 17:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nebtrx/46bcb82186daa7c915f8 to your computer and use it in GitHub Desktop.
Save nebtrx/46bcb82186daa7c915f8 to your computer and use it in GitHub Desktop.
# See commit changes
git whatchanged -m -n 1 -p <sha of merge commit>
# Delete branch
git branch -d the_local_branch
# Delete remote branch
git push origin --delete <branchName>
# Undoing commits while not losing the changes
git reset HEAD~1 --soft
# Squashing last 4 commits
git rebase -i HEAD~4
# Sync local master with remote
git reset --hard origin/master
# renaming branch
git branch -m <newname>
# updating branch list
git branch -r
git remote update origin --prune
# Find wich branch contains a commit
git branch -r --contains <commit>
## Renaming branch local and remotely
# create a local new branch on top of your current branch
# push that new branch
# make a new PR with the right destination.
# close the previous PR
# reference the "old" pull request from the new one; eg. Supersedes #123 (as commented below by Rivera)
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
# Check diff between branches
git diff --name-status master..<branch_name>
# Resolve conflicts while inside a rebase
git checkout --[theirs|ours] -- <file>
# Rebase and use their | ours changes to resolve possible conflicts
git rebase -X[theirs|ours] <branch>
# Recover deleted commits after a push force
git reflog
// ouput
1a410ef HEAD@{0}: reset: moving to 1a410ef
ab1afef HEAD@{1}: commit: modified repo.rb a bit
484a592 HEAD@{2}: commit: added repo.rb
// move the cahnegs to another branch
git branch recover-branch ab1afef
// check hisotry
git log --pretty=oneline recover-branch
# Search for text in previous commits
git grep <term> $(git rev-list --all)
# Search deleted file or search file history
git log --all --full-history -- <relative/path/to/file>
# force push to the current branch(without specifying the branch)
git push origin $(git rev-parse --abbrev-ref HEAD) -f -u
# untrack file
git rm --cached <file>
# update forked repos
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git pull upstream master
# removed untracked files/directories recursevely and forced
git clean -fd
# count line of codes of a repo
git ls-files | xargs wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment