DEV Community

abbazs
abbazs

Posted on • Edited on

GIT recipes

How to cherry pick a file from another branch in to current branch?

git checkout <other_branch_name> <files/to/grab in/list/separated/by/spaces> -p

example:

git checkout mybranch config/important.yml app/models/important.rb -p
Enter fullscreen mode Exit fullscreen mode

How to list branches by creation date?

git for-each-ref --sort='-authordate'
Enter fullscreen mode Exit fullscreen mode

What is the difference between git fetch and git pull?

  1. git fetch pull only the meta data from remote. Good to know without actually pulling data locally.
  2. git pull pulls the difference from remote. So first do a git fetch understand the difference and then do the pull only when ready.

How to get the status of all the repositories in a directory?

for d in */; do 
    if [ -d "$d/.git" ]; then 
        echo "$d"
        cd "$d"
        git status
        cd ..
    fi 
done
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
lakuapik profile image
David Adi Nugroho

a tip for you, run this on your terminal:

$ man giteveryday