Reputation: 31
A typical workflow I have is to checkout master
and type git reset --hard @{u}
.
From there I will checkout the branch I want to merge master with and merge master
.
Can I perform the steps of updating master
without changing to it? (This would help me not stash when changing)
For example, I am on branch A
which was branched from master
. master
has been worked on and I have a lot of changes and don't want to perform a stash, so instead of performing a
git stash
git checkout master
git reset --hard @{u}
git checkout A
git merge master
git pop stash (pseudo)
I want to be able to perform a git reset --hard @{u}
for master
while currently on branch A
,
Upvotes: 2
Views: 486
Reputation: 30858
Try git worktree
.
git worktree add /path/to/foo master
cd /path/to/foo
git reset --hard @{u}
# remove the working tree when it's not needed any more
git worktree remove /path/to/foo
It checks out master
in another working tree and does not affect the current working tree where A
has been checked out.
But, why would you insist on using git reset --hard
? git update-ref
is indeed a better solution.
Upvotes: 0
Reputation: 26066
Can I perform the steps of updating master without changing to it?
Yes, see this answer.
I don't think those answers involve performing a hard reset on it.
A hard reset does not make sense when you are not checking out the other branch.
If you weren't doing a merge, you could also avoid the stash
by using a soft reset rather than a mixed one, too.
So (almost) all your steps condense to a single branch
or soft reset
command as explained in that answer.
In general, your workflow seems strange. To update master
to be in sync with upstream, you would normally fast-forward merge
the changes. But there is no need to do so, you can base your work branch on top of a remote branch after a fetch
.
Furthermore, you would normally either merge master
into your local branch to keep them in sync, or rebase
your branch on top of master
; depending on your style of workflow (whether you want history to be more linear or not).
Using stash
, in general, should be a rare thing to do.
Upvotes: 1