I Need Help On Git

Tags: #<Tag:0x00007f0a32373960>

My branch shows its 110 commits ahead of the master branch which I have not made myself. how can I go on to work on a ticket with these commits? won’t they mess me up? Insookwa@DESKTOP-4T543HR MINGW64 ~/openmrs-core (master) $ git remote add upstream https://github.com/openmrs/openmrs-core.git fatal: remote upstream already exists.

Insookwa@DESKTOP-4T543HR MINGW64 ~/openmrs-core (master)
$ git pull --rebase upstream master
From https://github.com/openmrs/openmrs-core
 * branch                  master     -> FETCH_HEAD
Already up to date.

Insookwa@DESKTOP-4T543HR MINGW64 ~/openmrs-core (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 110 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

@mozzy @sharif @sacull

@insookwa try to do a git reset --hard upstream/master( this will delete all your local changes to master) and then do git pull --rebase upstream master

1 Like

You also could probably try git reset HEAD^ --soft(this will save your changes, back to the last commit) or git reset HEAD^ --hard(Discard changes, back to last commit)

1 Like

i get this
Insookwa@DESKTOP-4T543HR MINGW64 ~/openmrs-core (master) $ git reset --hard upstream/master HEAD is now at aed41971cc TRUNK-5941: Removing nested blocks from single statement lambdas,using method references where applicable (#3547)

Insookwa@DESKTOP-4T543HR MINGW64 ~/openmrs-core (master)
$ git pull --rebase upstream master
From https://github.com/openmrs/openmrs-core
 * branch                  master     -> FETCH_HEAD
Already up to date.

i have used git reset --hard origin/master and my brach was up to date with master/origin. but when i do $ git pull --rebase upstream master i become 110 commits ahead of the origin/master

check the logs here :https://pastebin.com/gvWhCdL0

@insookwa do a git fetch --all and then git push origin master then rebase again

2 Likes

Awesome . thanks @gcliff . work tree is now clean . thanks a lot

3 Likes

@insookwa . thats the normal behaviour.

just do “git push origin master” ,to update your origin/master branch with the latest changes/commits you pulled from the Upstream master with this git pull --rebase upstream master .

3 Likes

I may be a little late on this one! but every time a PR is merged into the openmrs-core repository, your openmrs fork goes N-commits behind, thus the message This branch is N commits behind openmrs:master. Therefore, before working on any ticket(s), it is advisable to pull the most recent changes from the upstream branch.

  1. git checkout master
  2. git pull --rebase upstream master
  3. git push --force-with-lease origin master

At this point, the message is; This branch is even with openmrs:master.

On the other hand, if you have worked on N-number of tickets and committed the changes to the local/remote master repository, the git status command will show the dreaded This branch is N commits ahead of openmrs:master. message (Considering one commit per ticket).

  1. git reset --hard HEAD~N, where N is the number of commits.
  2. git push --force-with-lease origin master.
5 Likes

well explained @miirochristopher :slightly_smiling_face:

2 Likes

git push --force-with-lease origin master

Do not do this. Do not push directly to master. Especially do not push to master with any variant of --force.

1 Like

My main git workflow goes:

(master)$ git pull
(master)$ git checkout -b my-feature
# make changes
(my-feature)$ git add [changed files]
(my-feature)$ git commit
# repeat the above as needed
(my-feature)$ git fetch origin
(my-feature)$ git rebase origin/master  # try --interactive some time, it's fun
(my-feature)$ git push [origin|upstream|fork] my-feature
# open a PR, repeat add/commit/fetch/rebase/push as needed
(my-feature)$ git checkout master
(master)$ git pull
# and we begin again :)

Hopefully that’s helpful.

4 Likes