Reputation: 5167
I am doing this command with git:
git push origin mybranch
It keeps saying "Every up to date" but nothing happened on the server side. I think I did something wrong before but I am not sure where:
Yesterday I did a commit with a commit number [c1] and pushed the commit to server. Then I tried to pull the update from another developer:
git pull origin another
Then I commit the pull with a commit number [c2] and pushed to server. But after the pull the project crashes often, so I decided to rollback the pull:
git checkout [c1]
Then I worked on [c1] and made 3 commits but didn't push to server. This evening when I tried to push the last commit [c5] to server it kept saying "Everything up to date" but the server branch always stays at [c2]. I did:
git branch
on my side and found I am at (no branch). Then I did a
git checkout -b newbranch
Then I see the newbranch replaced (no branch). Then I did
git push origin newbranch
Finally pushed to the server. However I don't know what happened during these commands? Thanks!
Upvotes: 1
Views: 2503
Reputation: 616
In GIT you should be on a branch to push some changes.
What happened ?
It is all because of the below command.
"git checkout [c1]"
Lets say at start you were on branch B1 and HEAD pointing to commit [c2]. If you checkout a commit sha directly, it puts you into a "detached head" state, which basically just means that the current sha that your working copy has checked out, doesn't have a branch pointing at it. And now you have commited 3 more commits(which were not on any branch). So, the only way to save you work is attaching your head to some branch. that is what you did by using command "git checkout -b newbranch"
What could have been done?
instead of checking out the commit [C1] directly,
Option1
If you don't need the changes of commit [c2], you could have reverted the [C2] by using "git revert [c2]"
Option2
If you don't need the changes of commit [c2] and you want remove it from git history as well then, you could have reverted the [C2] by using "git reset --hard HEAD^" and force pushed it using "git push -f"
Upvotes: 2
Reputation: 385
Most likely its because you missed the -u option (to track upstream branch) on your git push. It should have been
git push -u origin newbranch.
See this SO link for more details: How do you make an existing Git branch track a remote branch?
Upvotes: 1