We have the emergency fix ready, so let’s merge the master and emergency-fix branches.
First, we need to switch to the master branch:
[user@localhost] $ |
git checkout master |
Now, merge the current branch (master) with emergency-fix:
[user@localhost] $ |
git merge emergency-fix |
Since the emergency-fix branch was created directly from master and no other changes were made to master while we worked, Git treats it as a direct continuation of master. It can therefore “fast-forward,” aligning both master and emergency-fix to the same commit.
With master and emergency-fix now being identical, we can delete the emergency-fix branch as it is no longer needed.
[user@localhost] $ |
git branch -d emergency-fix |
Now, we can switch back to the hello-world-images branch and continue working. Add another image file (img_hello_git.jpg) and update index.html to display it.
[user@localhost] $ |
git checkout hello-world-images |
<!DOCTYPE html> <html> <head> <title>Hello World!</title> <link rel=”stylesheet” href=”bluestyle.css”> </head> <body> <h1>Hello world!</h1> <div><img src=”img_hello_world.jpg” alt=”Hello World from Space” style=”width:100%;max-width:960px”></div> <p>This is the first file in my new Git Repo.</p> <p>A new line in our file!</p> <div><img src=”img_hello_git.jpg” alt=”Hello Git” style=”width:100%;max-width:640px”></div> </body> </html> |
Now that we’ve completed our work, we can stage and commit the changes for this branch.
[user@localhost] $ |
git add --all |
We see that index.html has been modified in both branches. Now we’re ready to merge hello-world-images into master. But what will happen to the recent changes we made in master?
[user@localhost] $
|
git checkout master |
The merge failed due to a conflict between the index.html versions. Let’s check the status:
[user@localhost] $ |
git status
|
This confirms there’s a conflict in index.html, but the image files are staged and ready to be committed.
We need to resolve the conflict. Open the file in your editor:
<!DOCTYPE html> <html> <head> <title>Hello World!</title> <link rel=”stylesheet” href=”bluestyle.css”> </head> <body> <h1>Hello world!</h1> <div><img src=”img_hello_world.jpg” alt=”Hello World from Space” style=”width:100%;max-width:960px”></div> <p>This is the first file in my new Git Repo.</p> <<<<<<< HEAD <p>This line is here to show how merging works.</p> ======= <p>A new line in our file!</p> <div><img src=”img_hello_git.jpg” alt=”Hello Git” style=”width:100%;max-width:640px”></div> >>>>>>> hello-world-images </body> </html> |
We can see the differences between the versions and edit the file as needed:
<!DOCTYPE html> <html> <head> <title>Hello World!</title> <link rel=”stylesheet” href=”bluestyle.css”> </head> <body> <h1>Hello world!</h1> <div><img src=”img_hello_world.jpg” alt=”Hello World from Space” style=”width:100%;max-width:960px”></div> <p>This is the first file in my new Git Repo.</p> <p>This line is here to show how merging works.</p> <div><img src=”img_hello_git.jpg” alt=”Hello Git” style=”width:100%;max-width:640px”></div> </body> </html> |
Now we can stage index.html
and check the status:
[user@localhost] $ |
git add index.html
|
The conflict has been resolved, and we can use commit
to complete the merge.
[user@localhost] $ |
git commit -m "merged with hello-world-images after fixing conflicts" |
And delete the hello-world-images branch:
[user@localhost] $ |
git branch -d hello-world-images |