Languages
[Edit]
EN

Git / Bash - clone repository with all branches

9 points
Created by:
Emrys-Li
580

In this short article, we would like to show how to clone Git repository with all its branches.

Quick solution:

Where:

  • cd "!$:t:r" navigates to repository directory achieved from https://domain.com/path/to/repository.git
    • Where:
      • !$ returns last argument from previous command,
      • :t returns tailing part from the path (repository.git in our case),
      • :r returns only basename from the filename (repository in our case),
  • sed -n '/\/HEAD /d; /remotes/p;' prints only lines with remotes word, omitting lines with /HEAD word,
  • xargs -L1 git checkout -t takes input lines as arguments and calls for each line git checkout -t command.

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join