I assume that you have already worked on GIT and understand some of the basics. This blog is just to walk you through some quick steps to capture a snapshot of a remote branch, make changes and then push your new branch to bit bucket/git hub.
Let’s say your coworker was doing the changes in branch “DEV-1234”, and your work is dependent on that change. The DEV-1234 branch is not yet merged to *master branch. You are planning to create a new local branch and add changes on top of what was done for DEV-1234. Let’s walk through the steps.
Step 1: Get to know about all the new branches created. Do a “git fetch”, you will get all the new branches created after you cloned or pulled from the repo the last time.
Step 2: Checkout to the branch from where you want to take a snapshot, perform this command “git checkout DEV-1234”
Step 3: Now you are in DEV-1234 branch which has the changes you desire, but you can’t make changes in this branch and push it because it is not yours, so you do this instead “git branch DEV-1235”, since you were in DEV-1234 branch when you did the git branch command, it will create a local branch DEV-1235 which is exactly similar to the remote branch DEV-1234. You can confirm it by executing the command “git log –oneline”. You should see that logs are the same for both DEV-1234 and DEV-1235.
Step 4: Now checkout to your brand-new local branch. Do “git checkout DEV-1235”, now you are in the correct local branch, go ahead and make your changes.
Step 5: Are you done making the changes? Great run your unit tests and make sure things are working as expected.
Step 6: Remember that your branch is still only in local and not in the server. Go ahead and do “git push”, you will notice that since the branch is not available already in remote the git will complain with the below error message:
fatal: The current branch DEV-1235 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push –set-upstream origin DEV-1235
That’s it!!, now copy this command that GIT suggested, and you will have the DEV-1235 branch in the remote repository
Step 7: Login in to your github/bitbucket and create the pull request to merge to your master branch.
Step 8: Wait for the QA reviewer to approve your build and Peer reviewer to approve your code 😊
Step 9: Merge it to the *master branch.
You are all set!! . Please leave your comments if you found this article to be helpful.