Useful Git Commands

I have found Git to be the best code repository I’ve used in time as a web developer. I’ve made a list of some Git commands that I have found useful. Many of these I’ve added aliases to configs to improve my workflow.

I’ll update this list as and when I get time

Editing Your Config

  • global: git config –global –edit
  • local: git config –local –edit

Deleting Branches

  • from remote: git push origin :<branchname>
  • from local: git branch -D <branchname> (the -D will force it)

Working With Another Branch

  • show the file list: git ls-tree -r origin/<branch name> <path to file> 
  • show the file contents: git show origin/<branch name>:<path to file>
  • copy a file: git show origin/<branch name>:<path to file> > <path to move file to>

Working With Merges

  • show branches merged into a specific branch: git branch -a -v –merged <branch name>
  • as above but add  name filter: git branch -a -v –list <filter wildcard> –merged <branch name>

Listing Branches Using Refs

  • Details of all branches: git for-each-ref –sort=committerdate –format=’%(color:cyan)%(committerdate:short)%(color:white) ,%(color:green)%(refname:short)%(color:white) ,%(color:yellow)%(authorname)’

 

 

 

One Reply to “Useful Git Commands”

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.