Find the parent branch of REMOTE LOCAL git

How to get the name of the remote branch gitfrom which the local commit gitwas forked?

I assume this is a 4-step process, and that the first three steps may be as follows:


Step one: get the name of the current branch in the local git repo:
git rev-parse --abbrev-ref HEAD    


Step Two: Get the hash of the currently checked commit from the local repo:
git rev-parse HEAD          # full hash  


Step 3. Get the name of the upstream tracking branch on the remote git repository:
git rev-parse --abbrev-ref @{upstream}


Step Four: Get the name of the parent upstream tracking branch on the remote git repository:

? @ChrisJohnsen, , , , . , , , . , , .

bash, CentOS-, bash.

+4
2

, , :

gitk --all
git log --oneline --decorate --graph --all

script, temp . temp. , . , . , :

  • git branch -r (, origin/master, origin/dev origin/feature).

  • /

    commmand git rev-parse --abbrev-ref @{upstream} (, origin/master, ).

  • git branch -b origin-master origin/master        #Create a local branch origin-master from origin/master
    git branch -b origin-dev origin/dev
    git branach -b origin-feature origin/feature
    
  • temp

    origin-master temp (origin-master, origin-dev o rigin-feature). , ( Git). .

  • , origin-master origin-dev, - /, origin/dev.

  • git branch -D origin-master
    git branch -D origin-dev
    git branch -D origin-feature
    
+1

, , , .

, , ( ) ( git fetch) . , .

+1

Source: https://habr.com/ru/post/1691767/


All Articles