I pushed about 200 commits to the branch master
.
On another server the branch A
is checked out, but I need to checkout master
here.
I could execute git checkout master
and then immediately git pull
.
But then a old state is going live until git pull
is executed to update the branch.
Can I update a branch first and then check it out?
After running git fetch
, you can force master
to change to where origin/master
is:
git branch -f master origin/master
Then you can check it out:
git checkout master
Which will be at the state of origin/master
and you will not pass by the intermediate state it was before.
Here is a brief example (I am checked out on test
and change master
to the same place as test
):
> git log --graph --oneline
* d97b1f8 (HEAD -> test) - tata (1 second ago)
* e680fb5 - toto (9 seconds ago)
* 4515586 (master) - bar (24 seconds ago)
* e241705 - foo (28 seconds ago)
> git branch -f master test
> git log --graph --oneline
* d97b1f8 (HEAD -> test, master) - tata (9 seconds ago)
* e680fb5 - toto (17 seconds ago)
* 4515586 - bar (32 seconds ago)
* e241705 - foo (36 seconds ago)
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