Someone pushed a "new feature" branch to the shared repo:
git push -u new_feature_branch
Now, I would like to create a copy of this branch on my local machine in order to test the new feature.
What would be the easiest way to do this? (Do I need to fetch
/ pull
before checkout
?)
In order to checkout a remote branch you have to first fetch the contents of the branch. In modern versions of Git, you can then checkout the remote branch like a local branch. Older versions of Git require the creation of a new branch based on the remote .
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .
I generally find it unnecessary to use git fetch
. git pull
is sufficient. git pull
will synchronize your repository with the remote. The new_feature_branch will then be available.
git checkout new_feature_branch
will notice the branch in origin and create a new local tracking branch for you and switch to that branch.
git pull git checkout new_feature_branch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With