Home Questions - Answers How to clone a git tree or branch?

How to clone a git tree or branch?

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_pathCode language: Bash (bash)

For example

git clone https://github.com/alpinejs/alpineCode 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-ie11Code 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_pathCode 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/alpineCode 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!

Content Protection by DMCA.com

Download HitXP Mobile App

Get it on Google Play
Gurudevhttps://www.hitxp.com
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

FacebookLike
InstagramFollow
PinterestFollow
RSS FeedSubscribe
Sound CloudFollow
TwitterFollow
YoutubeSubscribe

Latest Articles

The Power of Democracy: How Free Societies Foster Innovation in Science and Technology

Democracy allows freedom of speech and thought, boosting creativity and innovation. This leads to scientific breakthroughs and technological advancements.

How does GOD helps us?

Do prayers really help? Do miracles happen when we are in trouble? Does God really help us in times of need? Are prayers enough to save us during bad times? How should we face problems?

Sanskrit poem on Ramayana – read in reverse becomes Mahabharata!

A Sanskrit poem about Ramayana when read in reverse direction becomes a poem on Mahabharata!

The difference between Itihasa and Puranas

Documentation of ancient Indian history and the historical events of Indian civilization in the form of Itihasa and Puranas - Ramayana and Mahabharata.

Latest Music Notations

Jai Shri Ram – Adipurush – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Jai Shri Ram from the 2023 Hindi movie Adipurush in Western and Indian Notations.

Sojugada Soojumallige – Garuda Gamana Vrishabha Vahana – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Sojugada Soojumallige from the 2021 Kannada movie Garuda Gamana Vrishabha Vahana in Western and Indian Notations.

Oo Antava Mava – Pushpa – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Oo Antava Mava from the 2022 Telugu movie Pushpa in Western and Indian Notations.

Kaa Chalige Bangalore (Tiningaa Miningaa Tishaaaa) – Salaga – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Tiningaa Miningaa Tishaaaa (Kaa Chali Ge) from the 2022 Kannada movie Salaga in Western and Indian Notations.
Content Protection by DMCA.com