This indicates renaming the branch was successful! Now there’s no trace of the add-python-file branch anymore. Now the branch with the original name should be removed. $ git push origin -delete add-python-file Naturally at this point, we want to delete the original one because we just changed the name. Now both the newly named branch and the original branch exist on the remote origin. Now let’s check what the remote looks like after the push: * add-code-file -> add-code-fileīranch 'add-code-file' set up to track remote branch 'add-code-file' from 'origin'. Remote: Create a pull request for 'add-code-file' on GitHub by visiting: Here’s the push: $ git push origin -u add-code-file As you learned, we can push this newly named branch as a new branch to the remote origin and then delete the previous one. But because the remote branch also exists, we need to update it too. But we can check that the branch indeed changed by running the git branch command: $ git branchĪt this point, we’ve only renamed the local branch. When we run this command, there will be no output. Then let’s change the name of the branch: $ git branch -m add-code-file Let’s check out the add-python-file branch: $ git checkout add-python-file Let’s verify this by running git branch: $ git branch These two branches also exist in the local repo. main branch and add-python-file branch exist on the remote repo Let’s start with a scenario where there is the main branch a feature branch called add-python-file in the remote repository. Let me show you a complete example that captures everything you learned today with a real Git repo. git rename my-branch my-cool-branch Example To create the alias, run the git config –global command as follows: git config -global alias.rename 'branch -m'Īfter running this command, you can rename branches with git rename instead of git branch -m. When you do this, every time you do git rename, it calls git branch -m behind the scenes. To make this change, you can create a git rename alias for the git branch -m. Wouldn’t it be easier if you could do git rename instead of git branch -m?
0 Comments
Leave a Reply. |