Reputation: 886
I am totally new to git and in an emergency to use git commands to rebase my local branch to remote master. Things happened like this.
1.I forked a repo Logan676/seadroid from haiwen/seadroid on Github
2.I created a new branch called lguo
on Logan676/seadroid
3.Then do some changes, commits. At the same time the origin master haiwen/seadroid
also updated by others.
4.Now I want to rebase lguo
to the latest origin master of haiwen/seadroid
.
I used commands below:
git fetch origin # Updates origin/master
git rebase origin/master # Rebases current branch onto origin/master
And the output in gitbash is: Current branch lguo is up to date
.
But team members told me that my branch was rebased to the forked repo master not the origin master. I am so confused about that, did I miss any command?
BTW, I notice someone wrote like this
git clone
git checkout -b dev_branch
[do some changes, commit]
git fetch origin
git rebase origin/master
git push origin HEAD:master
so should I add the last command line
git push origin HEAD:master
I am afraid to use that command, I worried that will damage the origin master? what should I do? Any help from you will be appreciated.
Upvotes: 1
Views: 3788
Reputation: 2045
The remote origin points to your clone Logan676/seadroid on github, not to haiwen/seadroid. Your local clone of Logan676/seadroid is not aware of the original haiwen/seadroid repository.
You need to add the original repository as an additional remote to your local clone:
git remote add haiwen [email protected]:haiwen/seadroid.git
Then you can do
git fetch haiwen
git rebase haiwen/master
Upvotes: 1
Reputation: 17481
While it is possible to push from local branch A to remote branch B, in this case both branches have diverged and the push will be rejected. You can still force push, but it would mean losing whatever commits happened in master since you created branch lguo.
I reccomend you do the following
git checkout master
git pull origin master
git merge lguo
This will probably need some merging. The resulting master branch has all the changes you did on lguo. Finally:
git push origin master
Upvotes: 1