Change branch after using the –branch arg
I want to change the branch after my repo was cloned with this command:
git clone --depth=50 --branch=master https://example.com/Repo.git Repo
How can I checkout now e.g. the develop branch?
When I execute:
git checkout develop
error: pathspec 'origin/develop' did not match any file(s) known to git.
Some commands I tried (which didn’t work):
git remote set-branches --add origin develop git fetch origin git pull origin develop:develop
One Solution collect form web for “Change branch after using the –branch arg”
When you cloned the project you have limited which branch to clone along with the number of commits to download.
Therefor you can’t switch branches to a different branch without updating your local repository since it will need to contain all the relevant data of the given branch.
In your case you will have to clone the full repo or to fetch the desired branch.
Switch to un cloned branch
# create a new branch with the desired name git checkout -b develop # pull the remote changes locally to your machine git pull origin develop
git clone --branch is very similar to passing
--[no-]single-branch option to the clone.
git clone --branch
Clone only the history leading to the tip of a single branch, either specified by the
--branchoption or the primary branch remote’s HEAD points at.
Further fetches into the resulting repository will only update the remote-tracking branch for the branch this option was used for the initial cloning.
If the HEAD at the remote did not point at any branch when
--single-branchclone was made, no remote-tracking branch is created.
Here you can see the different results in the attached screenshot