Skip to content

Latest commit

 

History

History
105 lines (71 loc) · 2.86 KB

Advanced-Git-Cheatsheet.md

File metadata and controls

105 lines (71 loc) · 2.86 KB

Advanced Git Cheatsheet

Working with hub

Install Github's command line utility hub:

On OSX:

$ brew install hub

From source:

$ git clone https://github.com/github/hub.git
$ cd hub
$ rake install prefix=/usr/local

Authorize hub

You need to authorize hub with your Github account using an oAuth token, follow the instructions illustrated in this comment to create the token and provide it to hub

Attaching Pull Requests to existing issues

To attach a PR to an existing issue use the following command:

When you work on a Fork

$ hub pull-request -b USERNAME_OF_UPSTREAM_OWNER:UPSTREAM_BRANCH -h YOUR_USERNAME:YOUR_BRANCH URL_TO_ISSUE

When you work on the same repository

hub pull-request -i 4

Where -i 4 is the issue's id.

Source: Stackoverflow question.

Remove folder from repo with history

git filter-branch -f --tree-filter 'rm -rf folder/path' HEAD

source blog post, Stack Overflow, git-scm

Compact Git Repo

After a git filter-branch you run the git compact command to remove empty directories from history.

git gc --aggressive --prune=now

Source: SO Question.

Move a folder to another repository with history

From Source Repository

git clone <git repository A url>
cd <git repository A directory>
git remote rm origin
git filter-branch --subdirectory-filter <dir to move> -- --all
mkdir <dir to move>
mv * <dir to move>
git add .
git commit

From Destination Repository

git clone <git repository B url>
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory>
git pull repo-A-branch master
git remote rm repo-A-branch

source blog post

Alternative and FASTER way to copy dir from repo to repo with history

mkdir /tmp/mergepatchs
cd ~/repo/org
export reposrc=myfile.c #or mydir
git format-patch -o /tmp/mergepatchs $(git log $reposrc|grep ^commit|tail -1|awk '{print $2}')^..HEAD $reposrc
cd ~/repo/dest
git am /tmp/mergepatchs/*.patch

source