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

4

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

I noticed in BitBucket that the new branch / branch was created successfully.

Now, another programmer needs to get the changes from that particular branch to his machine without compromising the ones he already has.

How do I do it?

    
asked by anonymous 17.02.2014 / 21:50

2 answers

10

It should 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 --track flag links the local repository to the remote and the -b flag tells git that a new branch must be generated because the checkout command has other functions.

This command will create a new branch local equal to the remote with the nickname <apelido_do_branch_local>

Example: my remote repository in GitHub is https://github.com/luizfilipe/repositorio in my local repository it is mapped to the nickname origin , I want to bring the new branch created with nickname 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 in GitHub is: https://github.com/luizfilipe/repositorio in my local repository it is mapped to the nickname origin , I want to bring up the branch of nickname branch1 , inside branch1local I use the command:

git pull origin branch1
    
17.02.2014 / 21:55
6

The command to use is:

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

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

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

git remote -v

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

git branch --remote --list
    
17.02.2014 / 21:55