Verify the status of the local repo using git status
, everything should be up to date, but nothing has been pushed up to the remote repo.
Push the changes to the remote repo git push origin main
...
It’s good practice to develop off branches and merge those changes into the main/develop branch (typically called known as trunk - main/develop).
Merging changes from remote into main
...
Because we are not working with a remote git repo, we can merge changes from one branch into the current using git merge
From the command line check that you are on the main branch using the command git branch
...
If you are not on the main branch type git checkout main
Now merge the feature branch feature/rev_will_not_be_televised using the command
Code Block |
---|
git merge feature/rev_will_not_be_televised |
You should see something like this
...
Because we made changes that git could detect, the merge was completed with no issues.
It’s good practice to delete the branch once the feature is complete. Let’s go ahead and delete the branch feature/rev_will_not_be_televised
Merge conflicts
If whilst you were making changes to your feature branch, someone changed the main branch, the main is considered to be ahead of the feature branch, this will cause a merge conflict.
Switch back to the feature/rev_will_not_be_televised branch
Delete the lines of text from the file (around lines 15-19) and save the file
Code Block |
---|
Just like the cities staggered on the coastline
In a nation that just can't stand much more
Like the forest buried beneath the highway
Never had a chance to grow
Never had a chance to grow |
Stage and commit the changes
Switch back to main, the lines will reappear because on this branch (the current state of your application) nothing else has been merged into it.
Remove lines 18-19 and save the file
Code Block |
---|
Never had a chance to grow
Never had a chance to grow |
Perform a git merge of feature/rev_will_not_be_televised into main.
You get an error
...
Git is very good at telling why an operation cannot be completed. It’s worth reading the messages carefully and following the instructions it gives you.
In this case, we haven’t staged and committed the changes we’ve made in main.
Stage and commit your changes.
Perform a git merge of feature/rev_will_not_be_televised into main.
...
Notice now that you have a merge conflict. This is because you made changes in branches and now you’re trying to merge them together.
Info |
---|
Always keep main and develop branches clean of any development. Merge into them, and keep them as the single version of the truth. |
...
The 7 less than symbols followed by HEAD indicates the beginning of where the current branch differs from the branch you are merging in.
The 7 equal symbols indicate where the current branch change ends.
The 7 greater than symbols followed by the branch name indicates where the merge branch is being inserted into the current branch.
We must decide which branch holds the truth or is it a combination of the two branches?
We’ve decided that the main branch is the truth.
Edit the file and remove the git indicators so that the text looks like this, save the file
Code Block |
---|
From the Indians who welcomed the pilgrims
And to the buffalos who once ruled the plain
Like the vultures circling beneath the dark clouds
Looking for the rain
Looking for the rain
Just like the cities staggered on the coastline
In a nation that just can't stand much more
Like the forest buried beneath the highway |
Stage and commit the changes on the main branch. You should notice that git no longer appends MERGING to the branch name.
Here is a visual view of the branches
...
We are going to simulate another team member merging the remote changes into the main branch
Create another folder called tm2 (not as a child off the current folder which should already be a git repo)
Clone the poetry project down into the tm2 folder using the command git clone <git repo URL>
Navigate into the poetry folder, it should default to the main branch.
Examine the file six_honest_serving_men.txt. Notice that it has the original poem content not the lines from the other poem.
Pull the changes of the remote branch feature/the_rev_is_happening into main
Code Block |
---|
git pull origin feature/the_rev_is_happening |
...
Examine the file six_honest_serving_men.txt. Notice that it has been updated. We need to update the remote repo.
Code Block |
---|
git push origin main |
Visit your remote repo and you should see that the main branch on the remote repo has been updated.