How to get GIT remote branch

Get GIT remote branch

Since Git is a distributed version control system, local and remote repositories may be different. Branches are also remote, but may not be local.
Let's look at the command to import a branch of a remote repository into a local repository.

1. Remote View remote repositories

The local repository may not have all the branches of the remote. You can view the list of branches in the remote repository with the following command.
git branch -r
[root@localhost myapp]# git branch -r
  origin/dev
  origin/master
  origin/release

2. View the remote repository branch source

You don't need to have the same source locally in the remote repository branch. If you just want to see it, checkoutyou can do it temporarily with a remote branch checkoutThe command is to switch to a different branch. If you enter the remote branch name here, you can temporarily checkout the remote branch.
git checkout [원격 브랜치 이름]
If the remote branch name is, origin/releaseyou can do the following:
[root@localhost myapp]# git checkout origin/release
Note: checking out 'origin/release'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

[root@localhost myapp]# git branch
* (detached from origin/release)
  master
After checking out, if you check with the branch command, * (detached from origin/release)you can see that it floats with. This branch will disappear when you check out another branch.
[root@localhost myapp]# git checkout master
Switched to branch 'master'
[root@localhost myapp]# git branch
* master

3. remote repository branch to the local branch checkoutto

If you want to permanently track a branch of a remote repository in a local branch, you can checkout with the following command.
git checkout -t [원격브랜치명]
If the remote branch name is, origin/releaseyou can do this:
[root@localhost myapp]# git checkout -t origin/release
Branch release set up to track remote branch release from origin.
Switched to a new branch 'release'
[root@localhost myapp]# git branch
  master
* release
When you do this, the remote branch name and the local branch name are checked out the same.
Sometimes there are multiple remote repositories, or if you overlap the local branch name that I created, you may need to rename the local branch. You can do it
with the name of the branch you want with the following command checkout:
git checkout -b [생성할 브랜치 이름] [원격 브랜치 이름]
If you want to receive remote origin/releasebranch as a local my_releasebranch checkout:
[root@localhost myapp]# git checkout -b my_release origin/release
Branch my_release set up to track remote branch release from origin.
Switched to a new branch 'my_release'
[root@localhost myapp]# git branch
  master
* my_release

Comments

Popular posts from this blog

Enabling Com Port on Hyper-V 2nd Generation VM / Windbg

DLL Injection using CreateRemoteThread in Windows 10

Using Overlapped I / O in DeviceIoControl