It is easy to clone a git repository to your local machine using the git clone command. But this command will fail with a fatal error if you simply try to clone a branch or a tree of the repository by using the branch or tree URL.
So first let us see the command to clone a git repository
git clone repository_path
Code language: Bash (bash)
For example
git clone https://github.com/alpinejs/alpine
Code language: Bash (bash)
However, if you try to clone its branch or tree https://github.com/alpinejs/alpine/tree/fix-ie11 using the above method, the command will fail.
git clone https://github.com/alpinejs/alpine/tree/fix-ie11
Code language: Bash (bash)
The above command will return an error message “fatal: repository ‘https://github.com/alpinejs/alpine/tree/fix-ie11/’ not found”
The trick is to use the branch flag to clone a specific branch or a tree from git repository as follows
git clone -b branch_name repository_path
Code language: Bash (bash)
So, to clone the branch fix-ie11 of the repository, instead of using the tree url use the root url and mention the branch name using the branch flag. The command hence would be
git clone -b fix-ie11 https://github.com/alpinejs/alpine
Code language: Bash (bash)
Note that we have used the master branch url of the repository and only mentioned the branch name in the -b option. Now the specific branch would be cloned to the local machine successully. Happy Gitting!