Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to checkout branch from master

sudhakar yala June 14, 2018

After cloning a repo checkout to "X" branch does nothing and it is a valid branch, if i switch to any other branch from master..and then switch to "X" it works but not directly from master.

After running git checkout X, nothing happens and no error.

When we run git branch it still shows master branch.

Need help on this.

3 answers

0 votes
Yann Delanoe
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 8, 2019

I had the same issue and the cause was that i had a file that had the same name than my branch on the root of my repo.

So a "git checkout X" command was checkouting the file instead of switching to the branch X.

0 votes
Caterina Curti
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 15, 2018

Hi @sudhakar yala,

Have you been able to resolve this? If yes, it would be awesome if you could share with us what was happening and how this has been addressed.

 

Cheers,

Caterina - Atlassian

0 votes
Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

HI @sudhakar yala

Welcome to the community!

As you mentioned in your description, you are in Master branch and running the git checkout X. so here X is nothing but master or any other branch?

"checkout" is the act of switching between different versions of a target entity like a branch, commit, files...

sudhakar yala June 14, 2018

Hi @Yogesh Mude, Thanks for the reply.

Yes X is another branch not master.

Yes i am unable to switch to X branch from master, however after switching to any other branch and switching back to X branch works fine.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

It should switch from any branch to any.

Is this X branch is created from bitbucket using create branch or git?

If this X branch is created from Bitbucket server then can you please try to create a new branch using below command from git and try to switch in between.

git checkout -b <branch_name>

sudhakar yala June 14, 2018

It works fine when we use git checkout -b <branch_name> and able to switch as well, but we do not want to create a new branch, X is existing valid branch, to which we are trying to switch. And we are unable to do so.

sudhakar yala June 14, 2018

[root@ululinxxx devlabsctl]# git branch -a
  develop
* eof-fix
  master
  remotes/origin/bat-env
  remotes/origin/X

You can see the last line, we are trying to switch to that.

for reference please see below lines.

[root@ululinxxx devlabsctl]# git branch
* master
[root@ululin033 devlabsctl]# git checkout ci
[root@ululin033 devlabsctl]# git branch
* master

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

HI @sudhakar yala

As you are using [root@ululin033 devlabsctl]# git checkout ci...but this ci is not listed in branch list.

sudhakar yala June 14, 2018

sorry the last line remotes/origin/X=ci, I just replaced it with X

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

HI @sudhakar yala

Its Ok, X branch is remote branch correct?

can you please use the below command and check.

git checkout --track origin/X

sudhakar yala June 14, 2018

Ok That's intresting it worked.

[root@ululin033 devlabsctl]# git branch
* master
[root@ululin033 devlabsctl]# git checkout ci
[root@ululin033 devlabsctl]# git branch
* master
[root@ululin033 devlabsctl]# git checkout ci
[root@ululin033 devlabsctl]# git branch
* master
[root@ululin033 devlabsctl]# git checkout --track origin/ci
Branch ci set up to track remote branch ci from origin.
Switched to a new branch 'ci'
[root@ululin033 devlabsctl]# git branch
* ci
  master

 

But now the question is why it did not work the way it should have been and is there any difference if we use git checkout --track origin/ci, instead of git checkout ci.

Will all the commit history be intact.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

HI @sudhakar yala

I am glad that I helped you to solve your problem.

For more details please have a look at the below article.

https://stackoverflow.com/questions/10002239/difference-between-git-checkout-track-origin-branch-and-git-checkout-b-branch/10002469?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

If you feel this answer is helped you to solve your issue then please don't hesitate to accept this answer, It will help others those who will face the same issue in future.

sudhakar yala June 14, 2018

Hi @Yogesh Mude, Thanks for the reply.

[root@ululin033 devlabsctl]# git checkout --track origin/ci
Branch ci set up to track remote branch ci from origin.
Switched to a new branch 'ci'

We do not want new branch to be created, we already have a remote branch ci, to which it needs to checkout, inspite of that its creating new branch.

Yogesh Mude
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 14, 2018

HI @sudhakar yala

Can you please check the git checkout local documentation using below command..

man git-checkout

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events