How do I get changes from a specific branch/branch of a remote repository in GIT?

Asked

Viewed 20,956 times

7

I created a new branch/branch on my local machine. So I made a commit and a push to the remote repository in Bitbucket.

I checked in Bitbucket that the new branch/branch was successfully created.

Now, another programmer needs to take the changes from this branch/branch specific to his machine without compromising the ones he already has.

How do I do?

2 answers

14


It must use the following command if it does not have the branch on the local machine:

git checkout --track -b <apelido_do_branch_local> <apelido_do_repositório_remoto>/<apelido_do_branch_remoto>

The flag --track connects the local repository with the remote and flag -b warns git that a new branch should be generated because the command checkout has other functions.

This command will create a new branch same location as remote with nickname <apelido_do_branch_local>

Example: My remote repository on Github is https://github.com/luizfilipe/repositorio in my local repository it is mapped to the nickname origin, I want to bring the new nickname created branch branch1.

The command to be executed will be:

git checkout --track -b branch1local origin/branch1

If it already has the local branch it should use:

git pull <apelido_do_repositório_remoto> <apelido_do_branch_local>

example: my remote repository on Github is: https://github.com/luizfilipe/repositorio in my local repository it is mapped to the nickname origin, I want to bring up the nickname branch update branch1, within the branch1local I use the command:

git pull origin branch1

7

The command to be used is:

git checkout --track nome-do-remote/nome-do-branch

This command will automatically create a local branch with the same remote name and the --track will connect the location with the remote whenever you make a git push.

To find out which are your remote servers you can use the command:

git remote -v

To find out which are your remote branches you can use the following command:

git branch --remote --list
  • 2

    Layman’s question: how do I find out the [remote-name]?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.