Follow these steps:
- We will start by checking out a local branch that tracks a remote branch:
$ git checkout -b remoteBugFix --track origin/stable-3.2 Branch remoteBugFix set up to track remote branch stable-3.2 from origin. Switched to a new branch 'remoteBugFix'
- The previous command creates and checks out the remoteBugFix branch that will track the origin/stable-3.2 branch. Therefore, for instance, executing git status will automatically show how different your branch is from origin/stable-3.2, and it will also show whether your branch's HEAD can be fast forwarded to the HEAD of the remote branch or not.
- To provide an example of how the previous step works, we need to do some manual work that will simulate this situation. First, we find a commit:
$ git log -10 origin/stable-3.2 --oneline f839d383e (HEAD -> remoteBugFix, origin/stable-3.2) Prepare post 3.2.0 builds
699900c30 (tag: v3.2.0.201312181205-r) JGit v3.2.0.201312181205-r
0ff691cdb Revert "Fix for core.autocrlf=input resulting in modified file..."
1def0a125 Fix for core.autocrlf=input resulting in modified file and unsmudge
0ce61caef Canonicalize worktree path in BaseRepositoryBuilder if set via config
be7942f2b Add missing @since tags for new public methods in Config
ea04d2329 Don't use API exception in RebaseTodoLine
3a063a0ed Merge "Fix aborting rebase with detached head" into stable-3.2
e90438c0e Fix aborting rebase with detached head
2e0d17885 Add recursive variant of Config.getNames() methods
- The command will list the last 10 commits on the stable-3.2 branch from the remote origin. The --oneline option will show the abbreviated commit hash and the commit subject. For this recipe, we will be using the following commit:
$ git reset --hard 2e0d178 HEAD is now at 2e0d178 Add recursive variant of Config.getNames() methods
- This will reset the remoteBugFix branch to the 2e0d178 commit hash. We are now ready to continue using the free benefits of Git when we have a remote tracking branch.
We are resetting to a commit that is accessible from the origin/stable-3.2 remote tracking branch; this is done to simulate that we have performed a Git fetch and new commits were downloaded for the origin/stable-3.2 branch.