Open-source Languages & Tools for z/OS

 View Only
  • 1.  Git Merge fails if branch is not available locally?

    Posted 10-28-2022 19:44
    The scenario is this.
    • Multiple users working on a repo
    • user a has branch A and user b has branch B
    • user a needs to merge branch B into branch A
    • merge fails as branch B is only on the server (remote) rather than local

    Using Git version 2.26.2-82 

    The workaround is to :
    • user a does a checkout branch B - this gets it local
    • user a does a checkout branch A - return to the users branch
    • user a can successfully do a git merge

    I've tried git fetch --all and it does not fetch branch B to the local repo.

    Thoughts?  Is this a bug in the git version I'm using? Known bug? 

    Other thoughts/suggestions.

    ------------------------------
    LionelDyck <><
    https://github.com/zigi
    https://github.com/lbdyck
    ------------------------------


  • 2.  RE: Git Merge fails if branch is not available locally?

    Posted 10-28-2022 20:12
    My experience is that the branch fetched from the server would be origin/BranchB.
    If I have a local BranchB I can merge from origin/BranchB or BranchB.

    Note:
    For sanity, it helps if origin/BranchB and BranchB are the same line of development but this is not guaranteed.
    UserA could create their own BranchB with completely different contents to UserB's BranchB.
    If UserB pushed BranchB, UserA ends up with their own BranchB and fetches origin/BranchB which are not the same. That is fine until UserA tries to push BranchB, which won't work.

    At that point, UserA could create BranchC from their local BranchB and push that, which would work.

    The branch is just a name pointing to a particular commit. Each user and the server have their own copies of the repository and the branch names can be different or point to different commits.

    ------------------------------
    Andrew Rowley
    Self Registered
    Ballarat AU
    ------------------------------



  • 3.  RE: Git Merge fails if branch is not available locally?

    Posted 10-29-2022 12:18
    Found the solution

    1.  do a git fetch --all
    2. then merge origin/branch-name

    I was missing the origin/ which seems to be required when a branch is not local, which only happens if one does a checkout for it.

    ------------------------------
    LionelDyck <><
    https://github.com/zigi
    https://github.com/lbdyck
    ------------------------------