# Switching git branches

**URL:** <https://forum.ansible.com/t/switching-git-branches/18288>\
**Category:** Ansible Project\
**Created:** [May 22, 2015, 4:30pm UTC](https://forum.ansible.com/t/switching-git-branches/18288 "2015-05-22T16:30:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Whittles](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Joe\_Whittles](https://forum.ansible.com/u/Joe_Whittles)\
**Post date:** [May 22, 2015, 4:30pm UTC](https://forum.ansible.com/t/switching-git-branches/18288/1 "2015-05-22T16:30:59Z")

</div>

Hey all – suppose I had the following task in a playbook:

`

- name: “Clone aire\_core repo”  
git:  
repo: “[git@bitbucket.org](mailto:git@bitbucket.org):joe/my\_repo.git”  
dest: “/home/me/my\_repo”

depth: 1  
version: “{{ git\_branch }}”  
key\_file: “~/.ssh/id\_rsa”  
update: true

`

I set `git_branch` to master, clone and everything is fine. However, should I choose to point my branch to `foo` at some point in the future, I get a complaint that git doesn’t have the `foo` branch.

I expected I could perhaps work around it without having to delve into code by adding a refspec attribute and seeing if it would fetch the relevant branch, to no avail.  
`  
refspec: “+refs/heads/{{ git\_branch }}:refs/remotes/origin/{{ git\_branch }}”

`

So is this desired behaviour, or is there something I’m missing? Am I really supposed to be tearing down my repo if I’m expected to be changing branches regularly?
