Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

89%
+15 −0
Q&A What's the correct way to merge a branch and its dependent branch back to master?

I think a branch is a set of commits Well, technically no, it's not. But first things first. DAG (Directed Acyclic Graph) Personally, Git became much more easier to understand after I've r...

posted 2y ago by hkotsubo‭  ·  edited 2y ago by hkotsubo‭

Answer
#7: Post edited by user avatar hkotsubo‭ · 2022-01-10T12:01:03Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And [a branch is just a pointer to one specific commit](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and updates the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` onto `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all the changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit hash.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will be like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And [a branch is just a pointer to one specific commit](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).[^1]
  • When you init a Git repository and create the first commit, Git by default creates the `master` branch (or, [for versions after October 2020](https://www.zdnet.com/article/github-to-replace-master-with-main-starting-next-month/), the [`main` branch](https://github.com/github/renaming)) and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and updates the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` onto `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all the changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit hash.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will be like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
#6: Post edited by user avatar hkotsubo‭ · 2021-10-14T15:55:08Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and updates the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` onto `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all the changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit hash.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will be like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And [a branch is just a pointer to one specific commit](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell).[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and updates the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` onto `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all the changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit hash.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will be like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
#5: Post edited by user avatar hkotsubo‭ · 2021-07-26T11:29:08Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and updates the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` onto `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all the changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit hash.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will be like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
#4: Post edited by user avatar hkotsubo‭ · 2021-07-23T20:06:15Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not.[^1] But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.[^1]
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
#3: Post edited by user avatar hkotsubo‭ · 2021-07-23T20:04:51Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not.[^1] But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • [^1]: Well, we *could* say that a branch is the set of all commits reachable from the commit it points to. But technically it's just a pointer to a commit.
#2: Post edited by user avatar hkotsubo‭ · 2021-07-23T19:58:56Z (over 2 years ago)
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Your situation seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
  • > _I think a branch is a set of commits_
  • Well, technically **no**, it's not. But first things first.
  • ---
  • # DAG (Directed Acyclic Graph)
  • Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.
  • Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").
  • And a branch is just a pointer to one specific commit.
  • When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:
  • ```none
  • +--------------+
  • | first commit | <-- master
  • +--------------+
  • ```
  • When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • ```
  • When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • new_branch
  • ```
  • Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • ```
  • ---
  • And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch | <-- another_branch
  • +---------------+
  • ```
  • And adding a new commit to `another_branch` will be like:
  • ```none
  • +--------------+ +---------------+
  • | first commit | <-- | second commit | <-- master
  • +--------------+ +---------------+
  • +---------------+
  • | new commit in | <-- new_branch
  • | new_branch |
  • +---------------+
  • +----------------+
  • | new commit in |
  • | another_branch | <-- another_branch
  • +----------------+
  • ```
  • Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.
  • A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.
  • ---
  • Based on the output provided in the comments:
  • ```none
  • Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
  • Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
  • Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
  • Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
  • ```
  • Just to explain this output, in the first line `725d9d1c11` is the commit hash (actually just part of it), and `ca99f826dc` is the parent commit.
  • Hence, your case seems to be exactly the one described above. In general terms, it's something like this:
  • ```none
  • A <- B <- C <-- master
  • D <- E <-- branch_A
  • F <- G <-- branch_B
  • ```
  • Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).
  • If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:
  • ```none
  • A <- B <- C
  • D <- E <-- branch_A
  • F <- G <-- branch_B, master
  • ```
#1: Initial revision by user avatar hkotsubo‭ · 2021-07-23T19:49:59Z (over 2 years ago)
> _I think a branch is a set of commits_

Well, technically **no**, it's not. But first things first.

---
# DAG (Directed Acyclic Graph)

Personally, Git became much more easier to understand after I've read things like [this](http://think-like-a-git.net/). The "*whoa*" moment was when it compares Git to a [DAG (Directed Acyclic Graph)](https://en.wikipedia.org/wiki/Directed_acyclic_graph). I'm not going into all the math theory, but just think of a Git repository as a series of nodes pointing to each other.

Each commit is a node in the graph, which points to other nodes: some are the data (folders/files), and some are the parent commits (the commits that "came before").

And a branch is just a pointer to one specific commit.

When you init a Git repository and create the first commit, Git by default creates the master branch and makes it point to that commit:

```none
+--------------+
| first commit |  <-- master
+--------------+
```

When you create another commit, Git creates another node for it, makes it point to the previous one and update the master branch to point to the newer commit:

```none
+--------------+     +---------------+
| first commit | <-- | second commit |  <-- master
+--------------+     +---------------+
```

When you create a new branch, Git simply creates another pointer, with a different name. Let's say my repo contains the two commits above and I do `git branch new_branch`. The result is:

```none
+--------------+     +---------------+
| first commit | <-- | second commit |  <-- master
+--------------+     +---------------+
                            ↑
                        new_branch
```

Git created the branch, by simply creating another pointer to the same commit. Now let's suppose I do `git checkout new_branch` (to actually "switch" to that branch) and create a new commit in it. The repo will be like this:

```none
+--------------+     +---------------+
| first commit | <-- | second commit |  <-- master
+--------------+     +---------------+
                            ↑
                     +---------------+
                     | new commit in | <-- new_branch
                     |   new_branch  |
                     +---------------+
```

---
And what if I create another branch from `new_branch`? It'll simply create another pointer to the same commit:

```none
+--------------+     +---------------+
| first commit | <-- | second commit |  <-- master
+--------------+     +---------------+
                            ↑
                     +---------------+
                     | new commit in | <-- new_branch
                     |   new_branch  | <-- another_branch
                     +---------------+
```

And adding a new commit to `another_branch` will be like:

```none
+--------------+     +---------------+
| first commit | <-- | second commit |  <-- master
+--------------+     +---------------+
                            ↑
                     +---------------+
                     | new commit in | <-- new_branch
                     |   new_branch  |
                     +---------------+
                            ↑
                     +----------------+
                     | new commit in  |
                     | another_branch | <-- another_branch
                     +----------------+
```

Now, if I want to merge all changes from both `new_branch` and `another_branch` to `master`, I just need to merge `another_branch`, because it already "contains" the changes from `new_branch`.

A merge basically finds the common ancestor between the 2 commits and apply all changes, starting from this common ancestor and ending in the target branch. In the example above, if I switch to `master` and do a `git merge another_branch`, it'll also apply the `new_branch` changes, because their commits are also part of the chain.

---
Based on the output provided in the comments:

```none
Fri Jul 23 10:42:47 2021 -0400 725d9d1c11 [ca99f826dc] (HEAD -> feature/ct-comparisons-VER-75425, origin/feature/ct-comparisons-VER-75425)
Thu Jul 22 16:27:48 2021 -0400 ca99f826dc [6498847a48]
Thu Jul 22 11:05:17 2021 -0400 6498847a48 [9b2ddff48d] (origin/feature/null-rows-VER-74021-VER-75002, feature/null-rows-VER-74021-VER-75002)
Thu Jul 22 11:02:59 2021 -0400 9b2ddff48d [37329f2ec7]
```

Your situation seems to be exactly the one described above. In general terms, it's something like this:

```none
A <- B <- C <-- master
          ↑
          D <- E <-- branch_A
               ↑
               F <- G <-- branch_B
```

Therefore, if you merge `branch_B` onto `master`, you'll end up merging `branch_A` as well (or, in other words, the commits from branch A will also be included in the merge).

If `master` has no other commits after `C`, the merge will be made using a simple fast-forward, and the repo will like this:

```none
A <- B <- C
          ↑
          D <- E <-- branch_A
               ↑
               F <- G <-- branch_B, master
```