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?

  • How do I git diff on a certain directory
  • How to copy a commit from one branch to another in git without any merging?
  • Git fatal: Reference has invalid format: 'refs/heads/master
  • What does 'track' mean when creating a new branch in git?
  • What does “Mark this commit” mean in gitk?
  • bitbucket git push not permitted
  • When I execute:

    git checkout develop
    

    I get:

    error: pathspec 'origin/develop' did not match any file(s) known to git.
    

    Any idea?

    Some commands I tried (which didn’t work):

    git remote set-branches --add origin develop
    git fetch origin
    git pull origin develop:develop
    

  • Equivalent in git of “hg cat” or “svn cat”
  • Revert reversion in git with branch, and readably
  • eclipse egit cannot connect to remote repository
  • Merge git submodule into main repository
  • git checkout: detailed meaning of “theirs” and “ours”
  • Cannot push, pull or merge git. “Working copy has uncommited changes”
  • 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

    --[no-]single-branch

    Clone only the history leading to the tip of a single branch, either specified by the --branch option 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-branch clone was made, no remote-tracking branch is created.


    Here you can see the different results in the attached screenshot

    enter image description here

    Git Baby is a git and github fan, let's start git clone.