ParkinT / mastering_git

The practice exercises and examples in the book 'Mastering Git' published by Packt Publishing
24 stars 14 forks source link

Add details for Remote Tracking Branches when cloning a repository with multiple branches #2

Closed ParkinT closed 8 years ago

ParkinT commented 9 years ago

Due to changes in Git 2.x the behavior with respect to remote-tracking branches (and 'fetch' or 'pull') is different. Further complicating matters, all the top search results point to StackOverflow pages that were written prior to this change.

Now, a git clone command will only bring in the master branch. In order to properly setup the remote-tracking-branches (when the cloned repository has other branches) you need to follow the advice in this StackOverflow topic (about halfway down the page);

for b in `git branch -r | grep -v -- '->'`; do git branch --track ${b##origin/} $b; done

This has worked for me reliably many times.

This needs to be properly described and included as part of the Addendum here.

techmag commented 9 years ago

Appreciate the update -- thank you.

git is far from the only project that suffers from the "old links are generally better" policy of most search engines. You should see the mess this creates learning Play for example. I wonder if a more elegant solution to the problem can be found and applied globally?

PS: I took many git courses and your rose to the top by a landslide...

ParkinT commented 9 years ago

Thanks, @techmag for the comment. Primarily, I wanted to capture this for myself (all too often an Internet search results in a hit on something I wrote months/years ago!). But, hopefully this will be useful for others in that predicament.

PS: I took many git courses and your rose to the top by a landslide...

I greatly appreciate the comment. Please share this sentiment on social media!

ParkinT commented 8 years ago

Closed in this commit