Skip to content

Instantly share code, notes, and snippets.

@davidnguyen11
Last active May 31, 2023 02:20
Show Gist options
  • Save davidnguyen11/d0fd4b468d5b2847d9aedb22e1668d18 to your computer and use it in GitHub Desktop.
Save davidnguyen11/d0fd4b468d5b2847d9aedb22e1668d18 to your computer and use it in GitHub Desktop.
Git tips

Disable vim in "git log" & "git branch"

git config --global pager.log false
git config --global pager.branch false

Get current branch name

Works with git version < 2.2

git rev-parse --abbrev-ref HEAD

Works with git version >= 2.2

git branch --show-current

Checkout file from different branch

git checkout <branch_name> -- <paths>

Git push with authentication

git push -u origin <branch_name>

Remove all branches except master

git branch | grep -v "master" | xargs git branch -D 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment