Assume I have a master branch with some commits I want to keep for later documentation and reference but remove them from the master (because I want the master to be on the same state as the upstream repo).
My approach now is, to
Now, my question is:
Often branches are shown in the following way, where (to my understanding) D
is the basis of the new branch.
A - B - C - D (master)
\
(new branch)
Is the branch "rebased" automatically or how would you call it? Would it then look like this?
A - B (master)
\
C - D (new branch)
Last and maybe most general question:
reset --hard
the master branch the right way to achieve my goal of getting my fork back to the upstream state (commit B
) without having my commits (C
and D
) merged?When resetting a local Git branch to remote, you will lose the changes you made locally. This step is optional, and you may choose to do it just in case something goes wrong or you want to go back to that work again in the future. Your work now is saved to the branch named backup_work.
In Git, this is called rebasing . With the rebase command, you can take all the changes that were committed on one branch and replay them on a different branch. For this example, you would check out the experiment branch, and then rebase it onto the master branch as follows: $ git checkout experiment $ git rebase master First, ...
This isn't a matter of updating the working tree and checking out a certain version of the content of tracked files. The git reset hard command actually points the HEAD right back to the old commit and any changes to tracked files in the working tree since then are discarded.
And to list all of your local branches, you use the git branch command. To collaborate with other developers on the same project and for them to view any changes you make, you need to push changes from your local branch to a remote repository. This leads us to remote branches. A remote branch refers to a branch that exists in a remote repository.
Nothing will "happen" to the branch, since a branch in git is just a lightweight, movable, disposable pointer. Commits are the real thing.
Yes, the overall plan is good, make a new branch to keep the most recent commits, reset master to where it should (I guess origin/master
), and this ref on your C,D commits will allow them to stay permanently.
Without creating the branch, they would ultimately be garbage collected, even if they'd stay in the reflog for a while.
And also no, your C and D commits won't be merged into your upstream master if you follow your announced course of action. Go for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With