I'm new to Git and I have made a mistake when trying to push the project onto Github using Git Bash. The project has been successfully uploaded onto Github. However, I later noticed that source code contains unwanted lines of code (e.g: "<<<<<<< HEAD"), as well as the commit message which should not appear within the source code. How can I rectify these errors, please? I'm including a couple of screenshots to display the unwanted comments. Thanks in advance!
-
2just edit the file to delete the unwanted stuff, and `git commit` again...? if you don't want those lines in the file, then simply remove them from the file. [shrug] – underscore_d Mar 17 '21 at 13:28
-
Thank you @underscore_d! That's a good answer and I'm wondering if there is a way using Git commands to avoid this problem in the future? – Lola Mar 17 '21 at 13:30
-
6Those strings are conflict markers, which should be removed before committing (while resolving the conflict). You just need to be more careful when doing merges. It has nothing to do with the fact that you used Git BASH. – isherwood Mar 17 '21 at 13:32
1 Answers
This is usually due to a merge conflict. Most cases it is because more than one person modified the file at the same time or you are still in the process of merging. You can check out this older answer on this topic if you are still having issues. In terms of what you can do to avoid this problem:
If you're the only one working on this project (with this git repo) then make sure you pull the most recent version before you start working.
Be sure to check the status of your files using
git status
before you make a new commit. This should tell you if you have any unmerged paths.After this you can take a look at any conflict markers (if they exist) and choose what you want to do next. You can reference this link if you need any more help with these steps. Personally, my flow of commands typically goes:
git status
git add examplefile
git commit -m "Merge message"
Then if everything looks good I'll push to my desired branch for example:
git push -u origin master
Lastly, if you need any more information on conflict markers this answer should hopefully be useful for you! Hopefully this helps, Git can be super confusing but its a super useful tool to have so once you get it down it's amazing!

- 446
- 4
- 10