How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

To check out a branch from a remote Git repository, you can follow these steps:

1. Fetch the remote branches

First, ensure that your local repository is aware of the remote branches by using git fetch. This updates your local references to the remote branches.

git fetch origin

2. Check out the remote branch

Once the remote branches are fetched, you can check out the desired branch using git checkout -b and specifying the remote branch.

Command:

git checkout -b <local-branch-name> origin/<remote-branch-name>

Explanation:

  • <local-branch-name>: The name you want to give to your local branch.
  • origin/<remote-branch-name>: Refers to the branch on the remote called origin (which is the default name for the main remote repository) and the branch you want to check out.

Example:

If the remote branch is called feature-branch and you want to create a local branch with the same name, you would run:

git checkout -b feature-branch origin/feature-branch

3. Alternative using git switch (Modern Method)

You can also use the git switch command (introduced in Git 2.23) to achieve the same thing:

git fetch origin
git switch -c <local-branch-name> origin/<remote-branch-name>

This is equivalent to checkout but is a clearer way to switch between branches.

Summary Steps:

  1. Fetch the latest branches: git fetch origin
  2. Check out the remote branch: git checkout -b <local-branch-name> origin/<remote-branch-name>

댓글

이 블로그의 인기 게시물

PYTHONPATH, Python 모듈 환경설정

You can use Sublime Text from the command line by utilizing the subl command

git 명령어

[gRPC] server of Java and client of Typescript

[Ubuntu] Apache2.4.x 설치

Create topic on Kafka with partition count, 카프카 토픽 생성하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Auto-populate a calendar in an MUI (Material-UI) TextField component

The pierce selector in Puppeteer