avatarPrakarsh Parashar

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

11620

Abstract

omen’s movements advocating for gender equality in an intersectional way, where feminism should meet the experiences of this demographic of women, is at her intersection of <b><i>culture</i></b>, race, and gender oppression that is at a cross-road with the traditional, white, female-focused movement in the first (1840–1920), second (1962–1980s), and possibly arguably even third (1990s) <a href="https://www.history.com/news/feminism-four-waves">waves of feminism</a> that mainly all focused on the experiences of oppression from a predominantly western white female perspective alone.</p><h1 id="034e">Female Gender Oppression: Population Control via The Medical Profession</h1><p id="531d">Kim Jiyoung’s friend falls pregnant, and what a drama it caused; this was around the time when the government implemented “birth control” policies they called “family planning.” Abortion was legal for medical related reasons. What if I told you that being born female was also considered a “medical problem” and a reason for her friend to consider abortion? And clearly some medical professionals felt the same way. The author cites this as a common dilemma for women throughout the 1980s-1990s. While the author does not go deep into this subject as part of the plot, I did do some investigation myself into this. According to the <i>Feminist Majority’s</i> short report they released in <a href="https://feminist.org/news/korean-women-pressured-to-abort-girl-babies-to-try-for-sons/">January 1997</a> they confirmed that:</p><blockquote id="cdaa"><p>“Although fetal sex identification and abortion are against the law in South Korea, women continue to feel pressure to abort girl fetuses in order to try for sons.”</p></blockquote><p id="5cf4">Also</p><blockquote id="fe88"><p>“Compared to a natural ratio of 105 boys born for every 100 girls (which later evens out to 1:1 since boys die earlier), some regions in South Korea have rates of 125 boys born to every 100 girls resulting in 30,000 fewer girls born each year than would be the case without sex-influenced abortions.”</p></blockquote><p id="9143">And</p><blockquote id="41f7"><p>“A Chinese government report in 1992 found the ratio in China at 118.5 boys to 100 girls, statistics which embarrassed the government enough that it never formally released the results.”</p></blockquote><p id="9f55">When looking the pressure Korean women face to have sons, taking a simple glance at the birth rate ratio would lead a critical mind to see the ratio supports the argument that the medical profession had what I would call “a silent compliance” to help embed and maintain female oppression, by aborting female babies. Sure, no doctor with his or her head on straight will announce to the world, “come to me for female terminations, I’ll gladly help you.” But that doesn’t mean it wasn’t going on. The stats on the birth rate ratio show that at this point in time, in the nineties when the rates were released, female terminations must have been carried out at a high rate.</p><p id="1f4d">What is key to note about the male to female birth rate ratio is: any parent will probably remember the scan they were given when their fetus was eighteen to twenty weeks old. Around this time, when you’re offered a nice photo of the baby, you can also <a href="https://www.healthline.com/health/pregnancy/when-can-you-find-out-sex-of-baby#medical-tests">learn the sex of the baby</a>. For the Korean women it’s at this point that terminations logically must have been happening for females babies. This is as late as five months into pregnancy; abortions done then come with a higher risk to the mother as stated in the research done by <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC9614144/"><i>Frontiers in Women’s Global Health’s</i></a><i> </i>2022 study across southern Ethiopia. Their report asserts that:</p><blockquote id="eb57"><p>“Second-trimester abortion accounts for 10–15% of all induced abortions, with varying rates across countries, and is responsible for two-thirds of major abortion complications. It is also associated with higher medical costs, morbidity, and mortality rates than first-trimester abortion.”</p></blockquote><p id="e44f">With only 10–15 % as a norm for abortions at this stage, we can assume it’s not the norm globally. The <a href="http://aidtowomencenter.org/abortion-secondtrimester"><i>Aid to Women Centre</i></a> also cites a lot of risks and complications post abortion for women who have second trimester abortions. The Korean women have been subjected to a health risk, for the sake of maintaining their cultural patriarchy, which is not something we see a lot of for the western woman, in western culture.</p><p id="d54f">If we further compare the western gender oppression to the Koren women’s via the outcomes for female babies, and the medical profession’s willingness to partake in oppression, and lastly the health risk of a woman choosing late termination (even if the practice was more common in the eighties-nineties), you see that this type of oppression is not a cultural norm in the west. It could be argued that pressure should be placed on the Korean medical profession for better regulation of abortion practices.</p><p id="67d5">For Korean women their intersection of cultural oppression includes a key aspect western woman do not have. Which is: from the womb, females leave a bad taste in society’s mouth. Whether you have a girl or a boy, generally speaking, for the western woman it is a cause for celebration, not abortion.</p><figure id="d363"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*i1XzuPmk2jAonENWjAYxTA.jpeg"><figcaption>Photo by <a href="https://unsplash.com/@thatsherbusiness?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">That’s Her Business</a> on <a href="https://unsplash.com/photos/white-ceramic-mug-on-white-ceramic-plate-8KHPeh9mNvs?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h1 id="3e35">The Role of Korean Women: Their ‘Double Jeopardy’ and Work</h1><p id="a483">Being a woman with another characteristic that can be used for oppression (such as race or class), has been defined as ‘a double jeopardy’ by the black feminist Frances. M. Beal, in her work <a href="https://en.wikipedia.org/wiki/Double_Jeopardy:_To_Be_Black_and_Female"><i>Double Jeopardy: To Be Black and Female (1969)</i></a><i>. </i>In relation to the Korean woman, her double jeopardy is being female and living in a <b>culture which defines her role in a specific way</b>. Korean females are often not shunned for working or discouraged from working. In the west, the “right to work” caused a ruckus from predominantly white women in the second wave (1963–1980s) of feminism, against white men’s oppression. But the Korean woman is often expected to work, not for herself but to support the males in her family so that <b>they can progress</b> in life. Woman will work in substandard conditions with risks to their health, for terrible wages, to gain a few pennies to rub together in the contribution pot of male success. In <i>Kim Jiyong, Born in 1982, </i>the author writes:</p><blockquote id="b3ac"><p>“This was at a time when people believed it was up to the <b>sons</b> to bring honour and success to the family. The family’s wealth and happiness <b>hinged upon male</b> success. The <b>daughters</b> gladly supported the male siblings.”</p></blockquote><p id="e10a">This narrative comes in a scene where we see a Korean lady struggling with work to provide for a man and fulfill her cultural duty. Yet she could not dream for herself, and she could not be a success, and she could not work in the profession of her own desire.</p><p id="f2e2">Where culture meets feminism from this angle of work and roles in society, is a need to recognise the “double jeopardy” for Korean women — that is focused on <b>cultural roles and norms</b> for her as a woman in the world of work. Outside of being white and female, the cultural roles for women often do look very different for the black, brown, and minority woman; I have said this before and will keep saying it.</p><p id="bac4">The Korean woman is in a similar position of not being able to pursue her dream of her ideal career, just like white feminists fought for the right to work against white men. However, what is unique to women in different communities is that it is <b>a necessity for them to work and they are expected to</b>, <b>but not for them</b>, for the <b>patriarchy</b>, in the context of Korean women. For black women this looks different which I do plan to write about in a future story. Sticking to the Korean women’s plight and experience, now, if this is not oppression worth noting, or checking the patriarchy’s behaviour to show them how it damages the Korean women, then I don’t know what is.</p><p id="f1a9" type="7">Where culture meets feminism from this angle of work and roles in society, is a need to recognise the “double jeopardy” for Korean women</p><h1 id="7d11">Education of Korean Girls and Women</h1><p id="7ff4">In addition to being expected to work minor jobs to support the patriarchy, the Korean woman’s education is sacrificed. Boys are prepared for school with the right equipment, books, lunches etc., as mentioned earlier. Later on, when it comes to further education, boys are encouraged to attend higher education to access the degrees that will land them high paying jobs. While girls are not put in this position, but it’s fine for them to work on lower paying jobs, in risky environments, to support this cultural norm and the patriarchy. If you’re a woman in the west, tell me: when was the last time this was expected of you, as a woman?</p><h1 id="3ac5">How Cultural Oppression Embraces Sexual and Physical Harassment</h1><p id="7490">One of the most heartbreaking things about the cultural oppression Korean women face, for me as a reader of the author’s work, was how vivid it was that sexual and physical harassment is something Korean girls should just get used to. It appeared to be a cultural norm, something that starts from an early age and doubles down on the learning Korean girls gain around their status being lower than boys.</p><p id="fe7a">It appears that if a girl or woman is a victim, she is questioned over what she possibly could have done to bring the assault on herself. We do see this today in the western culture at times; it would be a lie to say we don’t.</p><p id="a618">The difference is when comparing the western woman’s potential experience of the doubt around her experiences, and the Korean woman’s, culturally it seems more acceptable to disbelieve a Korean woman. Also, it’s more culturally acceptable to physically/sexually harass women. For women, it’s almost like harassment is an expected life experience that is a woman’s responsibility to avoid.</p><p id="669c">One of the most dramatic examples of this embedded culture was while Kim Jiyoung was at school. She was bullied by a boy, and the teacher blamed her. The truth only came out when another young girl was brave enough to raise her hand and say what she saw. Later on, we follow young Kim Jiyong’s story as she makes her way home from school. A boy follows her, and even attempts to intimidate her with sexual advances on the bus. Her father’s response is to ask her, “what did you do?” for her to bring on his attack.</p><p id="4479"><a href="http://dis.hanyang.ac.kr/lyceum-vol-1/sexual-harassment-in-south-korea/"><i>The Hangyang Dis Division of International Studies</i></a> backs up the ex

Options

periences of Kim Jiyoung; they reported in 2018:</p><ul><li>a sexual assault is reported across south Korea at a rate of 3 cases an hour.</li><li>98% of assaulters being men, and 86% of victims being women.</li><li>One of the most common places of assault happening in the workplace.</li></ul><p id="cca9"><a href="http://dis.hanyang.ac.kr/lyceum-vol-1/sexual-harassment-in-south-korea/">The <i>Hangyang Dis Division of International Studies </i></a>also says in their report:</p><blockquote id="cdd6"><p>“Before you ask yourself why these women don’t speak-out, you must first understand the culture background of their society.”</p></blockquote><p id="1008">Supporting the last point above, we see workplace sexual harassment when Kim Jiyoung enters the world of work, in the field of marketing. A male security guard takes it upon himself to install secret cameras in one female toilet, then uploads the images to a pornographic site. He shares his assault with other men in the workplace, the cat is only let out of the bag when the word reached Kim Jiyoung’s female friend via her boyfriend — who warned her to use a different bathroom. The women engage in sexual assault litigation against the company; then the male CEO of the company responds to the women who were victims of the pornographic website experience:</p><blockquote id="62fc"><p>“It’ll ruin this company’s reputation if word gets around in the field, The accused male employees have families and parents to protect, too. Do you really want to destroy people’s lives like this?”</p></blockquote><p id="3a9e">What we see here is sexual harassment at its finest, with a spoonful of misogyny mixed in. It could be argued that any boss would respond like this, especially a male boss, to protect their company. Yet the men themselves who were part of the sexual assault admitted what they did but see no wrongdoing — that’s the cultural dynamic around overlooking women and sexual assault the <i>Hangyang Dis Division of International Studies</i> is probably referring to in their citation about understanding culture, above.</p><p id="7201">When compared to western culture, this is not something that would be taken as lightly. It could even be argued that a CEO (for the good of their company) is more likely to disassociate with the offenders of sexual assault to protect their brand. <a href="https://en.wikipedia.org/wiki/Sean_Combs">Sean ‘Puffy’ Combs,</a> the American rapper who currently at the time of writing has <a href="https://www.latimes.com/entertainment-arts/business/story/2023-12-06/sean-diddy-combs-sexual-assault-harve-pierre-fourth-woman">four sexual assault</a> cases against him, has been dropped from all of his lucrative money making deals by big companies. <a href="https://en.wikipedia.org/wiki/Russell_Brand">Russell Brand,</a> who is also caught up in sexual assault cases, lost his <a href="https://www.theguardian.com/culture/2023/sep/19/youtube-suspends-russell-brand-revenues-channel">YouTube monetised channels</a>, and <a href="https://en.wikipedia.org/wiki/Jonathan_Majors">Jonathan Majors</a> was <a href="https://www.independent.co.uk/arts-entertainment/films/news/jonathan-majors-assault-projects-dropped-b2324039.html">dropped from his acting roles</a> due to his accusations of sexual assault; this has all happened in 2023 at the time of writing this. In the west what we see here is a different response to women’s sexual assault. We have a “cancel culture” for men. Korean has a “what did we really do wrong? You can’t cancel us” culture. For the fourth wave feminist, this is something to challenge when culture meets feminism. The patriarchy needs checking around their handling — literally of women and their bodies, which they feel are free to access for all.</p><figure id="550f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*fuRradtidxYvIirUNUppbg.jpeg"><figcaption>Photo by <a href="https://unsplash.com/@sandym10?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Sandy Millar</a> on <a href="https://unsplash.com/photos/gold-wedding-band-on-white-textile-8vaQKYnawHw?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h1 id="afc3">About Married Life and Korean Women’s Oppression</h1><p id="736c">For the Korean woman, she is often forced to give up work (if she has been lucky enough to find it), once she gets married. The pressure to get married is high, and her choice between work, marriage, and children is due to cultural expectations; this is not a woman who can have it all in any way shape or form. Once a woman is married it is an expectation, demand, and almost her duty to now start popping out babies — that are male, mind you. So that he can “bring the success, prosperity, and respect to the family,” as mentioned earlier.</p><p id="f56f">It was around 2014 when Kim Jiyoung finally secured work, battling through the sexism she faced as a Korean woman, which I deep dive into in my essay, <a href="https://readmedium.com/is-feminism-to-blame-for-korean-women-taking-down-the-patriarchy-870090bcc034?sk=ab5fcd0da5d394069b13b6107ad7dbe3"><i>Is Feminism to Blame For Korean Women Taking Down The Patriarchy</i></a><i>. </i>Then Kim Jiyoung left work, just as one in five Korean women quit their job citing: marriage, pregnancy, childbirth and care, or the education of their younger children, according to <a href="https://eng.kwdi.re.kr/inc/download.do?ut=A&amp;upIdx=101628&amp;no=1"><i>Women’s Lives Through Statistics in 2015, Statistics Korea</i></a><i>. </i>Around the time Kim Jiyong was faced with life changes the author asserted that:</p><blockquote id="fe06"><p>“The workforce participation rate of Korean women decreases significantly before and after childbirth. Its percentage starts at 63.8% for women aged twenty and twenty-nine, drops to 58% for women aged thirty to thirty-nine.”</p></blockquote><p id="da10">What this shows is that when culture meets feminism in this area for women, there is greater pressure, expectation, and demand for them to leave work to have male children, and if they do return to work after birth — to work to support their son’s progression. The latter, the author demonstrates, often means taking a lower paying job and giving up a career. Kim Jiyoung went from being a marketing executive in a male, sexist, environment — but she made it! — to considering part-time work in an ice cream parlour. This expectation is not a cultural norm for many of us western women, but one we need to be sensitive to, if we are to be inclusive female advocates.</p><p id="c887">Husbands also add to this pressure to leave work but fail to see what their wives are giving up. This plays out for readers clearly when married Kim Jiyoung is pressured by in-laws to have a child, then discusses it with her husband. They have barely been married five minutes at this point:</p><blockquote id="0c7b"><p>“And what will you be giving up <i>Oppa</i>?</p></blockquote><blockquote id="844d"><p>“What?”</p></blockquote><blockquote id="5852"><p>“You said don’t just think about what I’ll be giving up. I’m putting my youth, health, job, colleagues, social networks, career plans, and future on the line. No wonder all I can think about are the things I’m giving up. But what about you? What do you lose by gaining a child.”</p></blockquote><p id="e500">Her husband, true to his culture, did not see Kim Jiyoung’s personal goals, dreams, and rights to work go down the pan, in favour of producing child after child until she has a boy. Only to then take work well below her skills to provide for the male child.</p><p id="3643">For intersectionality to really make an impact in this fourth wave of feminism, as I said in the opening, eyes must be opened, ears must be fixed, and the advocate for women’s rights must step outside not only their <a href="https://readmedium.com/the-intersection-when-race-meets-feminism-the-unfinished-conversation-d39e2dda8062?sk=ecfa9780caf2ab4cc78d4d86dc2d29b3">race</a>, class, sexuality, able body, but also their<b> culture</b> to understand how oppression looks different for different demographics of women. This is how the patriarchy’s behaviour oppresses some women; the men do nothing to change a son’s position being more valuable than daughter’s from the moment they are conceived. They take this status norm in their culture as chance to exploit women sexually, physically, and even financially with Korea having the largest gender pay gap in the Asian countries. The patriarchy’s behaviour is culturally harming women; this is not my opinion, this is based on the data, statistics, and evidence presented. My message to the patriarchy is: don’t argue with me, argue with the evidence, and do something about it.</p><p id="0517"><b>What are your thoughts and feelings now that you’ve seen cultural oppression by reading these words?</b></p><p id="319a"><i>Thanks for your readership, I hope my writing gave you something to think about. If I’ve caught you in a good mood or you’re feeling kind, you can buy me a coffee here: <a href="https://www.buymeacoffee.com/meandmymuse">https://www.buymeacoffee.com/MeAndMyMuse</a>. Why not follow me for more of my thought-provoking muse?</i></p><p id="b84b"><b>Further reading:</b></p><div id="b269" class="link-block"> <a href="https://readmedium.com/is-feminism-to-blame-for-korean-women-taking-down-the-patriarchy-870090bcc034"> <div> <div> <h2>Is “Feminism to Blame” For Korean Women Taking Down The Patriarchy?</h2> <div><h3>And they are using their wombs!</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*dlbaZB-GAzJKEHITvpsrLA.jpeg)"></div> </div> </div> </a> </div><div id="e914" class="link-block"> <a href="https://readmedium.com/the-intersection-when-race-meets-feminism-the-unfinished-conversation-d39e2dda8062"> <div> <div> <h2>The Intersection When Race Meets Feminism: The Unfinished Conversation</h2> <div><h3>Who is wiling to have it?</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*9ssL5l5Hjai5yhg3riC6Jg.png)"></div> </div> </div> </a> </div><div id="9ef5" class="link-block"> <a href="https://readmedium.com/intersection-where-class-meets-feminism-are-the-women-of-latin-america-class-less-dc3ff334e521"> <div> <div> <h2>Where Class Meets Feminism: Are the Women of Latin America Class-less?</h2> <div><h3>And whose responsibility is it to improve their lot?</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*b5hexyyoSq8tEGd10Fdf2w.jpeg)"></div> </div> </div> </a> </div><p id="08a1"><i>For more of the good stuff, follow <a href="https://medium.com/fourth-wave">Fourth Wave</a>. Have you got a story, essay, or poem that focuses on women or other disempowered groups? <a href="https://readmedium.com/submit-to-the-wave-7c92f095e86f">Submit to the Wave!</a></i></p></article></body>

Git Branching Made Easy

This is the second article in the series of articles on Introduction to Git. The first article can be found here. Note that the first article is a prerequisite for this article.

When working on a big project, several features of the project are being developed simultaneously. Git branching helps serve this purpose in an extremely efficient way. Let us try to understand it using an example. Suppose there are two developers — DevA and DevB. Both are working on a project together. This is how the commit history of their Git repository currently looks.

After some time they feel that it would be better if DevA start working on featureA and DevB starts working on featureB. In a world without branching both the developers would commit to the same line of development. DevA would see the commits and changes made by DevB and vice-versa. Won’t things become confusing? It would become extremely difficult to isolate the work of DevA from the work of DevB.

Git Branching provides an easy mechanism to develop several features of your project simultaneously and then later merge those features in the main project. It helps to isolate your work completely from that of other members of the team. I think we would better understand the power of Git Branching once we begin working with it. So let’s jump right into it.

In a nutshell, this is how Git branching works. Whenever you want to develop a certain feature in your project, you branch into another line of development. And once you finish implementing the feature, the feature branch can be merged into the original line of development (also called the master branch).

Orange color depicts the branch in which featureA is implemented, while the Cyan color depicts the branch in which featureB is implemented. Branching helps maintain isolation in the development environment for both the developers.

What is a Git Branch?

All this time (in the previous article) we were developing in a linear line, without any branches. Well, that was a lie! We were still on a branch, the master branch. This is the default branch that Git creates when you do a git init . Remember, when you did a git log , you would see a master written on your latest commit.

Every branch has a name. Stickers denote the name of the branches. The Master branch is the default branch created when we do a git init.

Generally, the master branch is considered the main line of development. For implementing a specific feature you branch into another feature branch and then later merge the feature branch into the master branch. Thus the master branch is meant to be permanent while other branches die after the purpose for which they were created has been fulfilled (after merging them into another branch).

How Git Branching works internally? How to create a Git Branch?

Currently, this is how our repository looks like -

>>> git log
commit e097d8da357fe97c36c7178f0b770ae44b1f1f3c (HEAD -> master)
Author: pprakarsh <prakarshparashar@gmail.com>
Date:   Thu May 21 10:24:55 2020 +0530
changed file2
commit 6642a0de776b52bbe993555a4bf14aed060afea2
Author: pprakarsh <[email protected]>
Date:   Sun May 3 22:14:12 2020 +0530
added another line in file1
commit 155891ca19d94f67159a992c77923818b57d74a5
Author: pprakarsh <[email protected]>
Date:   Sun May 3 10:41:06 2020 +0530
created file1, created subDir1 and created file2 in it

Notice master written on the latest commit.

To create a new branch feature1 , execute the following command

>>> git branch feature1
>>> git log
commit e097d8da357fe97c36c7178f0b770ae44b1f1f3c (HEAD -> master, feature1)
Author: pprakarsh <prakarshparashar@gmail.com>
Date:   Thu May 21 10:24:55 2020 +0530
changed file2
commit 6642a0de776b52bbe993555a4bf14aed060afea2
Author: pprakarsh <[email protected]>
Date:   Sun May 3 22:14:12 2020 +0530
added another line in file1
commit 155891ca19d94f67159a992c77923818b57d74a5
Author: pprakarsh <[email protected]>
Date:   Sun May 3 10:41:06 2020 +0530
created file1, created subDir1 and created file2 in it

You will now notice master, feature1 written on the latest commit. Thus a new branch feature1 has been created which points to the same commit pointed by the master branch.

To see all git branches execute the command below.

>>> git branch
  feature1
* master

Notice the asterisk on the master. This denotes that the master is our current working branch.

feature1 branch originates from Commit-3. (Currently, no commits have been created in feature1 branch)

So, to conclude:

  1. Create a new branch using git branch branchname .
  2. When a new branch is created, say, branch2 created from branch1, then branch2 points to the latest commit in branch1 as we just saw.
  3. git branch to see all working branches in your repository

Diving Deep into Git References

Let us digress from the topic for a moment and talk about Git References. A good understanding of Git References helps a lot in the understanding of how Git Branches work internally.

So, What are Git References? And how are they useful?

References in Git provide a mechanism to mark important objects so that they can be easily referred to later. Suppose for a certain section of your project you would like to refer to the code in commit-2 frequently. This would require that we know the commit hash for the commit object. But, Instead of executing a git log and then searching for the commit hash repeatedly, we can use the reference that we have created to refer to that commit object. We will see how to create references in a while.

There are two types of references: 1. heads 2. tags

Execute the following command to see how these references are stored in the .git directory.

>>> tree .git/refs
.git/refs
├── heads
│   ├── feature1
│   └── master
└── tags

Let us take a look into both heads and tags one by one -

heads

Remember when we executed git log earlier, we also saw HEAD -> master . What is this HEAD? The HEAD is nothing but a pointer to the branch we are currently working on. An exception to this is the detached HEAD state (Don't worry! We will talk about this in a while). If we are working in the master branch we will see HEAD -> master .

>>> git log
commit e097d8da357fe97c36c7178f0b770ae44b1f1f3c (HEAD -> master, feature1)
Author: pprakarsh <prakarshparashar@gmail.com>
Date:   Thu May 21 10:24:55 2020 +0530
changed file2
commit 6642a0de776b52bbe993555a4bf14aed060afea2
Author: pprakarsh <[email protected]>
Date:   Sun May 3 22:14:12 2020 +0530
added another line in file1
commit 155891ca19d94f67159a992c77923818b57d74a5
Author: pprakarsh <[email protected]>
Date:   Sun May 3 10:41:06 2020 +0530
created file1, created subDir1 and created file2 in it
HEAD points to the current working branch, master branch.

Suppose if we switch to feature1 branch. (We were currently on the master branch. We had created the feature1 branch but we were still on the master branch). To switch to feature1 branch execute the following command.

>>> git checkout feature1
Switched to branch 'feature1'
>>> git branch
* feature1
  master

We have changed our current working branch to feature1 .

>>> git log
commit e097d8da357fe97c36c7178f0b770ae44b1f1f3c (HEAD -> feature1, master)
Author: pprakarsh <prakarshparashar@gmail.com>
Date:   Thu May 21 10:24:55 2020 +0530
changed file2
commit 6642a0de776b52bbe993555a4bf14aed060afea2
Author: pprakarsh <[email protected]>
Date:   Sun May 3 22:14:12 2020 +0530
added another line in file1
commit 155891ca19d94f67159a992c77923818b57d74a5
Author: pprakarsh <[email protected]>
Date:   Sun May 3 10:41:06 2020 +0530
created file1, created subDir1 and created file2 in it

Notice that, instead of HEAD -> master , we now have HEAD -> feature1 on our latest snapshot. Since we switched to feature1 branch, our HEAD now points to feature1 . Thus HEAD is nothing but a pointer to the current branch in our git repository.

After switching to the feature1 branch, HEAD now points to feature1.

Now once again, a moment of truth! The branch we have been talking about all this while is also nothing but a reference object. It is a pointer to the latest commit in the branch. When a new commit object is created in a branch, the branch pointer is simply updated to point to the new commit object.

So, How is Git able to identify the current commit object that we are working on, it fetches the HEAD reference object, which provides the branch reference object (for the current working branch) and then the branch reference object provides the commit object. Hence the denotation HEAD -> branch .

In our git repository, currently, references — HEAD->feature1 , feature1 and master point to the same commit object. While the HEAD reference object points to the feature1 reference object.

To conclude: 1. branch reference objects keep track of our latest commit on the branch. The branch reference object is updated only when a new commit object is created in the branch. 2. HEAD reference object keeps track of our current working branch. The HEAD reference object is updated whenever the current working branch is switched to another branch.

tags

Tags are mainly used to mark important points (commits) in your Git commit history. While heads are inbuilt references, tags are required to be created.

Suppose commit-2 is an important commit and would be required to be referred to frequently. We can create a tag that points to commit-2. Whenever it would be required to refer to the commit-2 object, we can use this tag.

Since it is not required to know tags for understanding Git Branching. We will talk about it in another article. The link to the article would be available here.

Continuing with Git Branching

So, we looked at how to create branches, how to switch between branches, and list all branches. We also looked at what is a HEAD reference object and that the branch is nothing but a pointer (reference object) to the latest commit of the branch. Now, let us make some changes and create some more commits in our new feature1 branch. Note that we are currently on our feature1 branch. Execute the following commands to create two new commits in the feature1 branch.

>>> echo "I have been created in feature1 branch." > file3
>>> git add file3
>>> git commit -m "added file3"
[feature1 693f09b] added file3
 1 file changed, 1 insertion(+)
>>> echo "Another commit in file3" >> file3
>>> git add file3
>>> git commit -m "change in file3"
[feature1 ef154d8] change in file3
 1 file changed, 1 insertion(+)
>>> git log
commit ef154d8ae3bac0e2bdcd8102381e49a3a5c480ee (HEAD -> feature1)
Author: pprakarsh <prakarshparashar@gmail.com>
Date:   Sat Jul 18 12:23:49 2020 +0530
change in file3
commit 693f09b8c388a684156f9654d99ad5c4b8f2133c
Author: pprakarsh <[email protected]>
Date:   Sat Jul 18 12:18:07 2020 +0530
added file3
commit e097d8da357fe97c36c7178f0b770ae44b1f1f3c (master)
Author: pprakarsh <[email protected]>
Date:   Thu May 21 10:24:55 2020 +0530
changed file2
commit 6642a0de776b52bbe993555a4bf14aed060afea2
Author: pprakarsh <[email protected]>
Date:   Sun May 3 22:14:12 2020 +0530
added another line in file1
commit 155891ca19d94f67159a992c77923818b57d74a5
Author: pprakarsh <[email protected]>
Date:   Sun May 3 10:41:06 2020 +0530
created file1, created subDir1 and created file2 in it

We can see that the feature1 branch is 2 commits ahead of the master branch.

Commit history of our current Git repository. feature1 pointer moves to the latest commit, while HEAD points to the working branch pointer (feature1)

Now we would like to merge our feature1 branch into the master branch. So, How can we do this?

Merging Branches Overview:

When we finish implementing a particular feature, we would want to merge it into the branch it originated from. When we want to merge branch2 into branch1, we have two possible scenarios:

Fast Forward Merge:

A Fast Forward merge is performed when the Lowest common Ancestor of branch1 (reference object) and branch2 (reference object) is branch1 (reference object).

Note that when we are talking about branch1/branch2 (reference object), we are talking about the latest commit on that branch.

Lowest Common Ancestor of branch1 and branch2 is the latest commit of branch1

Note that the HEAD points to branch1. Thus if want to merge branch2 into branch1, our current working branch must be branch1.

Fast Forward merge is simple. During a Fast-Forward merge, the branch1 pointer is simply moved to the same commit where the branch2 pointer points.

In a Fast-Forward merge, the branch1 pointer simply moves to the position of branch2 pointer. The HEAD pointer follows the branch1 pointer.
Redrawing the previous image

3-way Merge:

The 3-way merge is performed when the Lowest Common Ancestor of branch1 (reference object) and branch2 (reference object) is some other commit object, not branch1 (reference object) or branch2 (reference object). This generally happens when some new commits have been added to the original branch after the new branch has been created.

Lowest Common Ancestor of branch1 and branch2 is neither pointed by branch1 pointer nor by branch2 pointer. Commit-3, Commit-5, and Commit-7 will be involved in a 3-way merge

Instead of moving the branch pointer forward. A new commit is created — merge commit. This commit has two parents — one from branch1 and one from branch2. Changes in both branch1 and branch2 are merged and combined into this new merge commit.

On merging, a new merge commit, commit-8 is created in branch1, which incorporates the changes made in both branch1 and branch2.

So, now we have a good idea about the two possible scenarios when merging branch2 into branch1. Let us now try out the fast-forward merge and the 3-way merge in our git repository.

Merging Branches Implementation:

Simply doing a git log may not be the best way when dealing with branches. A better command for visualizing git branches is shown below.

>>> git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
* ef154d8 - (HEAD -> feature1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - (master) changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

The output becomes colorful and neat. You need not write this gigantic command repeatedly, you can set an alias for this command (to say git lg).

>>> git config --global alias.lg "log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

Now executing git lg will give us the same pretty output.

>>> git lg
* ef154d8 - (HEAD -> feature1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - (master) changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

We see that the feature1 branch is two commits ahead of the master branch. The Lowest Common Ancestor of the feature1 branch and the master branch is the commit pointed by the master. Thus, this is the case of a Fast-Forward merge. We want to merge the feature1 branch into the master branch. Thus HEAD must point to master. So, the first step is to checkout to the master branch (the branch we want to merge into).

>>> git checkout master
Switched to branch 'master'
>>> git branch
  feature1
* master
>>> git lg
* ef154d8 - (feature1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - (HEAD -> master) changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

To merge the feature1 branch into the master branch, execute the following command.

>>> git merge feature1
Updating e097d8d..ef154d8
Fast-forward
 file3 | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 file3
>>> git lg
* ef154d8 - (HEAD -> master, feature1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Observe the output of the git merge feature1 command. The output shows Fast-forward merge. On executing git lg we see that the master now points to the same commit object as feature1 and HEAD points to the master.

The feature1 branch pointer is now useless, so we can delete the feature1 branch.

>>> git branch -d feature1
Deleted branch feature1 (was ef154d8).
>>> git branch
* master
>>> git lg
* ef154d8 - (HEAD -> master) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Notice that there is no feature1 branch anymore.

Let us now create a new branch branch1 and try doing a 3-way merge. For this, we would need to create some new commits as well. Execute the following commands to create a new branch branch1 .

>>> git branch branch1
>>> git branch
  branch1
* master
>>> git lg
* ef154d8 - (HEAD -> master, branch1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

We are currently in the master branch. We will create a new commit object in the master branch. Currently, master and branch1 both point to the same commit object.

>>> echo "Another commit in master" >> file3
>>> git add file3
>>> git commit -m "file3 changes"
[master f614763] file3 changes
 1 file changed, 1 insertion(+)
>>> git lg
* f614763 - (HEAD -> master) file3 changes (10 seconds ago) <pprakarsh>
* ef154d8 - (branch1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Notice that the master now points to the new commit object. We will now switch to branch1 . The HEAD would now point to branch1.

>>> git checkout branch1
Switched to branch 'branch1'
>>> git branch
* branch1
  master
>>> git lg
* f614763 - (master) file3 changes (8 minutes ago) <pprakarsh>
* ef154d8 - (HEAD -> branch1) change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

We will now create a new commit in branch1 .

>>> echo "creating file4" > file4
>>> git add file4
>>> git commit -m "created file4"
[branch1 9e2566a] created file4
 1 file changed, 1 insertion(+)
 create mode 100644 file4
>>> git lg
* 9e2566a - (HEAD -> branch1) created file4 (3 seconds ago) <pprakarsh>
| * f614763 - (master) file3 changes (10 minutes ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Notice the divergence at the commit object ef154d8 . Both commit objects f614763 (belonging to the master branch) and 9e2566a (belonging to the branch1 branch) contains a reference to the same parent commit object ef154d8.

Creating another commit object in branch1 .

>>> echo "another line in file4" >> file4
>>> git add file4
>>> git commit -m "file4 changes"
[branch1 0b17834] file4 changes
 1 file changed, 1 insertion(+)
>>> git lg
* 0b17834 - (HEAD -> branch1) file4 changes (7 seconds ago) <pprakarsh>
* 9e2566a - created file4 (14 minutes ago) <pprakarsh>
| * f614763 - (master) file3 changes (24 minutes ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

We can see that new commit object 0b17834 has been created in branch1.

Let us now merge branch1 into the master branch. Notice that the Lowest Common Ancestor of the branch1 reference object (0b17834) and the master reference object (f614763) is a different commit object (ef154d8). Therefore, it is a 3-way merge. But, first, we need to switch to the master branch.

>>> git checkout master
Switched to branch 'master'
>>> ls
subDir1  file1  file3
>>> git lg
* 0b17834 - (branch1) file4 changes (11 minutes ago) <pprakarsh>
* 9e2566a - created file4 (24 minutes ago) <pprakarsh>
| * f614763 - (HEAD -> master) file3 changes (34 minutes ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Notice that the content of the repository does not show file4 , because file4 blob object cannot be accessed via the current commit object f614763 .

Execute the following command to merge branch1 into the master branch.

>>> git merge branch1
Merge made by the 'recursive' strategy.
 file4 | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 file4
>>> git lg
*   15357ad - (HEAD -> master) Merge branch 'branch1' (15 seconds ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (15 minutes ago) <pprakarsh>
| * 9e2566a - created file4 (29 minutes ago) <pprakarsh>
* | f614763 - file3 changes (39 minutes ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

The merge can be seen clearly by executing the git lg command. A new merge commit object (15357ad ) has been created, which contains changes in both the master branch and branch1. The master now points to this commit object.

If we are certain that branch1 servers no further purpose, we can delete branch1 by executing the git branch -d branch1 command. I choose not to delete it.

The case of Merge Conflicts

Now, we understand how a Git merge works and we also know how to do a Git merge. If we are merging two branches, changes in both the branches are incorporated in the merge. But, what if we change in the same part of the same file in the two branches. Clearly, both changes cannot be incorporated in the final merge. This results in a merge conflict. How do we resolve these merge conflicts?

In file2.txt, changes in the same part of the file lead to a merge conflict. Which change should be incorporated in the merge? — Tuesday or Wednesday

An important point to consider here is that merge conflicts can happen only in the case of a 3-way Merge. In the case of a Fast-Forward merge, changes are made in only one branch, thus merge conflict is not possible.

Let us see how to resolve a merge conflict. Firstly, we will create a new branch branch2 in our git repository.

>>> git branch branch2
>>> git branch
  branch1
  branch2
* master
>>> git lg
*   15357ad - (HEAD -> master, branch2) Merge branch 'branch1' (3 hours ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (3 hours ago) <pprakarsh>
| * 9e2566a - created file4 (3 hours ago) <pprakarsh>
* | f614763 - file3 changes (3 hours ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

Notice that a new branch branch2 has been created which points to the same commit object as master (15357ad). Also, note that we are currently in the master branch. We will create another commit object in the master branch.

>>> echo "Today is Tuesday" > file5
>>> git add file5
>>> git commit -m "file5 added, Tuesday"
[master 2a4af24] file5 added, Tuesday
 1 file changed, 1 insertion(+)
 create mode 100644 file5
>>> git lg
* 2a4af24 - (HEAD -> master) file5 added, Tuesday (11 minutes ago) <pprakarsh>
*   15357ad - (branch2) Merge branch 'branch1' (3 hours ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (3 hours ago) <pprakarsh>
| * 9e2566a - created file4 (4 hours ago) <pprakarsh>
* | f614763 - file3 changes (4 hours ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

We can see that a new commit object has been created in the master branch. We will switch to branch2 now and create a new commit in branch2 . On switching to branch2 , we will see that there is no file5 in the working directory. This is because we are currently on a different commit object (15357ad).

>>> git checkout branch2
Switched to branch 'branch2'
>>> git branch
  branch1
* branch2
  master
>>> git lg
* 2a4af24 - (master) file5 added, Tuesday (16 minutes ago) <pprakarsh>
*   15357ad - (HEAD -> branch2) Merge branch 'branch1' (3 hours ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (3 hours ago) <pprakarsh>
| * 9e2566a - created file4 (4 hours ago) <pprakarsh>
* | f614763 - file3 changes (4 hours ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>
>>> ls
subDir1  file1  file3  file4

We will now create a new commit object in branch2 . We will create file5 in branch2 as well, with the same content as in the master branch but the name of the day.

>>> echo "Today is Wednesday" > file5
>>> git add file5
>>> git commit -m "file5 added, Wednesday"
[branch2 206760e] file5 added, Wednesday
 1 file changed, 1 insertion(+)
 create mode 100644 file5
>>> git lg
* 206760e - (HEAD -> branch2) file5 added, Wednesday (31 seconds ago) <pprakarsh>
| * 2a4af24 - (master) file5 added, Tuesday (18 minutes ago) <pprakarsh>
|/  
*   15357ad - Merge branch 'branch1' (3 hours ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (3 hours ago) <pprakarsh>
| * 9e2566a - created file4 (4 hours ago) <pprakarsh>
* | f614763 - file3 changes (4 hours ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

A new commit object 206760e has been created in the branch2 branch. We can see a divergence at commit 15357ad . This commit object 15357ad serves as a parent for commit objects — 2a4af24 (in themaster branch) and 206760e (in the branch2 branch). Now let us switch back to the master branch and try to merge branch2 into the the master branch.

>>> git checkout master
Switched to branch 'master'
>>> git merge branch2
Auto-merging file5
CONFLICT (add/add): Merge conflict in file5
Automatic merge failed; fix conflicts and then commit the result.

On executing the git merge command, we will see that our merge has failed. This is because git cannot resolve the conflict on its own. We will have to manually resolve the conflict.

Run git status , this will provide the name of the files which have conflicts.

>>> git status
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)
Unmerged paths:
  (use "git add <file>..." to mark resolution)
both added:      file5
no changes added to commit (use "git add" and/or "git commit -a")

We will see that file5 is causing a merge conflict. Now open file5 using the editor of your choice. You will see something like this. Everything below <<<<<<< HEAD and above ======= belongs to the latest commit in the current working branch (master in this case) while everything between ======= and >>>>>>> branch2 belongs to the latest commit of the other branch (branch2 in this case).

<<<<<<< HEAD
Today is Tuesday
=======
Today is Wednesday
>>>>>>> branch2

Edit the file and resolve the conflict. Now your file would look something like this.

Today is Wednesday

Then execute git add filename to mark the file as resolved and finally execute git commit to commit the changes and complete the branch merging process.

>>> git add file5
>>> git commit
[master 4cf897d] Merge branch 'branch2'
>>> git lg
*   4cf897d - (HEAD -> master) Merge branch 'branch2' (2 minutes ago) <pprakarsh>
|\  
| * 206760e - (branch2) file5 added, Wednesday (32 minutes ago) <pprakarsh>
* | 2a4af24 - file5 added, Tuesday (49 minutes ago) <pprakarsh>
|/  
*   15357ad - Merge branch 'branch1' (4 hours ago) <pprakarsh>
|\  
| * 0b17834 - (branch1) file4 changes (4 hours ago) <pprakarsh>
| * 9e2566a - created file4 (4 hours ago) <pprakarsh>
* | f614763 - file3 changes (4 hours ago) <pprakarsh>
|/  
* ef154d8 - change in file3 (5 days ago) <pprakarsh>
* 693f09b - added file3 (5 days ago) <pprakarsh>
* e097d8d - changed file2 (9 weeks ago) <pprakarsh>
* 6642a0d - added another line in file1 (3 months ago) <pprakarsh>
* 155891c - created file1, created subDir1 and created file2 in it (3 months ago) <pprakarsh>

On running git lg we can clearly see that the branch2 has been successfully merged into the master branch. A new commit object has been created (4cf897d) which incorporates the changes of both the branches after the merge conflict resolution.

This completes our discussion on Git Branching. An important point to consider is that although we have discussed only two branches at a time, however in practice there can be nesting of multiple branches. The idea is that we consider only two branches at a time, merge them into one and then pick another two branches and so on.

Notice the nesting of maser branch, Branch-A, Branch-B, and Branch-C

Detached HEAD state

From our earlier discussion in the beginning of the article about Git references, we understand, branch is nothing but a reference (pointer) to the latest commit in the branch. We also talked about HEAD being a pointer to the current branch (HEAD-><branchname>). In a detached HEAD state, the HEAD points to some other commit (not the branch). This enables developers to move the HEAD to a different commit object and re-create the state of working directory same as that of another commit.

Detached HEAD state, HEAD pointing to Commit-2, instead of branch1 (HEAD->branch1).

You can execute this command to move HEAD to another commit object.

git checkout <commit-hash>

You can further make changes to your repository in detached HEAD state by branching to a new branch, allowing you to play around with the commit snapshots that you have saved.

This concludes our discussion of Git branching. Hope you found this article helpful! Let me know your thoughts in the comments below. Next article, we will learn in depth about tracking changes in Git repository.

The first article in this series (on Git Internals) can be found here.

Git
Git Branch
Git Branching
Git Branching Model
Git Internals
Recommended from ReadMedium