52 commits behind master

Viewed 2807

I made some changes in my local repository and pushed those in the remote branch, when I created a Pull Request for the same, I noticed that the branch contains all the commits I have made against the master, going back to 3 months. I also got the message that I am "52 commits behind the master" which I am assuming is because my code is not merged with the master (Please let me know if I am wrong in this assumption). I wanted only the latest commit to go to the branch I have created. One of options I thought about was pushing the specific commit to a new branch and then create a PR for it against the master, but it seems all the commits will be pushed till the specific commit unless I change the order using rebase.

I wanted to know what would be the better option, sync the commits or change the order using rebase and then push only that specific commit to the local branch?

Any help would be appreciated Note:I have recently started using git(bitbucket) and I'm struggling to grasp it and don't want to mess things up with the companies code, so there is a good chance that this question might not make sense.

I have tried to push the latest commit to the remote branch, but it seems to push all the commits till the latest commit. One of the option is to use rebase, but I am not really sure how I do it and whether it should be used.

2 Answers

It depends on your needs. If you only want to push your commit to the master, The safest way is to use cherry-pick from your branch to the master. It's perfectly safe because you don't have to force-push.

  1. Find the commit hash: git log.
  2. Checkout to master: git checkout master.
  3. Realign with master git pull or git pull upstream master if you're using upstream branch.
  4. Check that you're aligned with master: git status.
  5. Cherry pick without commit: git cherry-pick -n <commit-hash>
  6. Commit: git commit -m <commit message>
  7. Check the log, before pushing: git log. You can also check the diff: git diff origin/master.
  8. Push to master: git push.

You can just use simple rebase comment for updating your local repo,

git pull --rebase --autostash

Sometimes you will get merge conflicts, don't worry you can resolve that manually and use git rebase --continue

"52 commits behind the master" this because your local repository is not up-to-date.

Related