
Pull Branch From Github in Git
π How to Pull a Branch from GitHub
When working with GitHub, you may need to pull a branch to get the latest updates or work on a specific feature branch. Hereβs how you can do it.
π Steps to Pull a Branch from GitHub
1οΈβ£ Check Existing Branches
First, check the branches available in the remote repository:
git branch -r
This will list all remote branches, e.g.:
origin/mainorigin/developorigin/feature-branch
2οΈβ£ Fetch Latest Changes from Remote
Before pulling a branch, update your local repo with the latest data:
git fetch origin
3οΈβ£ Pull a Specific Branch
β If the branch already exists locally:
Switch to the branch and pull updates:
git checkout feature-branchgit pull origin feature-branch
β If the branch does NOT exist locally:
Download and switch to the branch:
git checkout -b feature-branch origin/feature-branch
or
git switch --track origin/feature-branch
4οΈβ£ Verify the Pulled Branch
Check the current branch:
git branch
The active branch will have a *
next to it.
π₯ Example: Pulling a Feature Branch
git fetch origingit checkout -b new-feature origin/new-featuregit pull origin new-feature
π― Summary
β
Fetch the latest changes β git fetch origin
β
Check available branches β git branch -r
β
Pull an existing local branch β git checkout branch-name && git pull origin branch-name
β
Pull a new branch β git checkout -b branch-name origin/branch-name
Let me know if you need further help! ππ