Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git checkout automatically fetch first?

Say I have a command that looks as follows:

git checkout -b my-branch origin/dev

Assuming I have already fetched from origin before, so I know it has a dev branch, do I need to run git fetch before git checkout, or will checkout always fetch up to the latest commit in the remote branch?

like image 422
IQAndreas Avatar asked Sep 26 '26 15:09

IQAndreas


1 Answers

git checkout -b branch origin/branch will check out from the remote repository without fetching the repository. The checked out branch will be what the branch looks like on the remote repo.

Note: Your local repository will not have the updated knowledge of the remote repository, so git branch -a may not show the remote branch you are checking out or it may show an older reference to it.

like image 52
ferrants Avatar answered Sep 29 '26 10:09

ferrants