It might be that sometime in a project, someone will say, you to take a clone from a specific branch (not from master) and will request you to push your changes or raise PR for that branch. In such situation, below commands can help you:
1. First check all the branches in remote
git branch -r
It will show you all the branches available in remote. It should have the requested branch also.
2. For example, here I am creating a new branch development.
3. Now when I will do git branch -r , then it will show me this branch. (Git pull is pre-requisite here)
4. Now what I will do is, I will create a local branch which will point to development branch.
git branch development_deepak origin/development
Note: It does not switch to that newly created branch. You still remains in master.
5. Now you need to switch to that created branch.
git checkout development_deepak (my local branch)
6. Now in this branch, when you will push, then there are 2 options:
1-> If you want to create a branch in remote (same local branch name), then use : (Recommended)
git push origin HEAD
What it will do, is create a branch in rmeote with your changes. Now you can raise your PR for this branch changes.
2-> git push origin HEAD:development
It will directly push the changes to the remote branch you were tracking. (If you have the permission)
No comments:
Post a Comment