Search notes:
GIT: Switch to remote branch after cloning a repository
First, we need to create a repository that acts as the remote one:
git init -q repo
touch file-1
git add file-1
git commit -q file-1 -m '+ file-1'
A new branch, named
dev
is created (
git switch -c
), another file added and commited to it:
git switch -q -c dev
touch file-dev
git add file-dev
git commit -q file-dev -m '+ file-dev'
The repository is switched back to the master branch so that the repository, when cloned will check out this branch:
git switch -q master
We're now ready to clone the «remote» repository:
git clone -q repo repo.clone
A simple git switch dev
figures out that the repository should switch to the branch with the same name in the remote repository:
git switch dev
ls -1
shows both files that are also present in the
dev
branch of the remote repository.
ls -1
The output of
git branch
confirms we're in the «right» branch:
git branch