What does - - mean in git checkout?

Asked

Viewed 1,302 times

4

When we use the git checkout nomedoarquivo what difference with git checkout -- nomedoarquivo?

I don’t know what changes using that --?

1 answer

4

The command git checkout "nome" (without --), will work the same way git checkout -- nome(with --) when there is no branch with the same name as the filing cabinet.

If there is a branch and file with the same name in the project, then the user has to specify which one he wants to checkout.

  • git checkout -- nome to choose the filing cabinet
  • git checkout nome to choose the branch

The -- serves to avoid confusion. Indicating that the user is checking out a file and not a branch with the same name.

Git is smart enough to try to match the command if there are no files and branchs with equal names. That’s why you didn’t see any difference in the results of the commands.

In fact, it is not only with branchs that ambiguity can occur. As explained in the documentation link at git checkout disambiguation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.