![]() ![]() If your changes would be overwritten by the attempt to switch branches, then git won't just allow you to switch branches because you would lose data. It is one of the four commands in Git that prompts interaction with the remote repository. Well, sometimes you can - such as in the case you describe. What Does git push Do git push updates the remote branch with local commits. 1414 How to compare a local Git branch with its remote branch. This may rarely be the option you'd want, but it's easy enough to do if it is what you want. Default behavior of 'git push' without a branch specified. For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull (1) and other commands. (Recall that only having one worktree and index is what necessitates git's default behavior so if you don't want that, you can make more worktrees.) ĥ - You can discard your changes. First of all, when pushing for the first time, do: git push -u origin hp1:team/hp1. git commit -m "wip"Ĥ - You can check out the other branch to a new worktree and index. This is why, when pushing for the first time, you must set an upstream: git push -set-upstream origin/master However, you can also configure the upstream for individual branches. As long as you don't push them to a shared repository, it's easy to undo the commit anyway. Pushing a Branch to a Different Remote You can configure a default remote, which is usually set up to be origin. If you do have deletions, you can still make it work, but rather than work around that it probably just makes more sense to use one of the other methods I've listed at least in those cases.ģ - You can go ahead and commit your changes. unless your changes include deletion of files) you can use the form of checkout to pull the changes back later. git stashĢ - You can create a temporary branch for your changes. Then after you're done looking at the other branch, you can come back to the branch where the changes are and unstash the changes. If you want to switch branches without bringing your local changes with you, you have several options.ġ - You can stash your changes. Your changes are in the worktree and maybe the index at this point, but by default you only have one of those (not one per branch) so switching branches without bringing along your changes would mean discarding the changes. This tutorial introduces the stash command of git, which allows you to easily move the changes to the correct branch. Utility aside, it's really the only sensible default behavior for git. This may not be what you expected, but it's often very useful. You can and if you do, the uncommitted changes come with you. I can't switch branches before committing? ![]()
0 Comments
Leave a Reply. |