Search code examples
gitcommitrebase

git mainline 5 commits ahead of local mainline


If i started working on a feature from mainline and I make 1 commit. However, by the time i finish the mainline has been committed 5 more times.

Is it considered that I branched? even though i didn’t create a branch? if so, what would my branch be called? git status shows it still called mainline.

How do i sync to mainline. I read that rebase is the scenario i am in. when inrebase, it says rebase complete and up to date, however i do not see the latest changes of the other commits in my source code.


Solution

  • There is two branch the local one and the remote one, classic way and easy way is to name local and remote with the same name.

    So in your case, you are in this situation

                         A---B---C---D---E mainline on the server
                        /
                   X---Y---Z mainline
    

    but for your local git doesn't know the update on the server, it has this vision

                   X---Y   origin/mainline
                        \---Z mainline
    

    so all is ok, you local git needs to fetch the new status of origin/mainline with

    git fetch
    

    will brink you in this situation on your local git

                         A---B---C---D---E origin/mainline
                        /
                   X---Y---Z mainline
    

    Then you will be able to merge or rebase your branch:

    • merge
                         A---B---C---D---E origin/mainline
                        /                 \
                   X---Y---Z---------------M mainline
    
    • rebase:
    
                   X---Y---A---B---C---D---E--Z'   mainline
    

    I recommend rebase in your case