How to pull a specific branch in GIT


To pull a specific branch in Git, you can use the git pull command with the name of the branch you want to pull from:

$ git pull <remote> <branch-name>

For example, to pull the development branch from the origin remote repository, you can use:

$ git pull origin development

This command will fetch the latest changes from the development branch in the remote repository and merge them into your local branch that tracks the remote branch.

Note that if you haven’t checked out the branch you want to pull into your local repository yet, Git will create a new local branch that tracks the remote branch for you automatically.

If you want to avoid automatically merging the changes, you can use the --no-commit option with the git pull command. This will fetch the changes from the remote branch but won’t automatically merge them, allowing you to review and manually merge the changes.

$ git pull --no-commit <remote> <branch-name>

Once you’ve reviewed the changes, you can manually merge them using the git merge command.

$ git merge <remote>/<branch-name>

This will merge the changes from the remote branch into your current branch.

Alternatively, you can also use the git fetch command to download the latest changes from the remote repository, and then use the git merge command to merge the changes from the specific branch into your local branch.

$ git fetch <remote>
$ git merge <remote>/<branch-name>

This will merge the changes from the remote branch into your current branch.

Note that when pulling or fetching changes from a remote repository, you should always make sure that you have committed or stashed any changes in your local repository to avoid conflicts.