# How to automatically checkout git repository after FetchContent\_MakeAvailable

**URL:** https://discourse.cmake.org/t/how-to-automatically-checkout-git-repository-after-fetchcontent-makeavailable/4807
**Category:** Usage
**Created:** [January 10, 2022, 9:47am UTC](https://discourse.cmake.org/t/how-to-automatically-checkout-git-repository-after-fetchcontent-makeavailable/4807 "2022-01-10T09:47:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [January 10, 2022, 9:47am UTC](https://discourse.cmake.org/t/how-to-automatically-checkout-git-repository-after-fetchcontent-makeavailable/4807/1 "2022-01-10T09:47:18Z")

</div>

I am using FetchContent\_MakeAvailable in my project, and the code is:

```auto
include(FetchContent)
FetchContent_Declare(opencv
  GIT_REPOSITORY "https://github.com/opencv/opencv.git"
  GIT_TAG "origin/master"
  SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/opencvc"
)
FetchContent_MakeAvailable(opencv)

```

It can fetch `opencv` repository sucessfully. However, I need to manually checkout master branch.

Is it possible to automatically git checkout master by FetchContent\_Declare or FetchContent\_MakeAvailable.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [January 10, 2022, 9:58am UTC](https://discourse.cmake.org/t/how-to-automatically-checkout-git-repository-after-fetchcontent-makeavailable/4807/2 "2022-01-10T09:58:12Z")

</div>

The topic has been discussed before.  
The module only guarantees that the right commit is checked-out. If you really need to check out a branch, you have to do it by yourself.
