How to solve GITHUB Commit Conflicts?
What are GIT commit conflicts? As a flexible version control system, GIT provides a great feature of committing changes to the local branch to the origin branch.
So since it pretty easy to commit then why conflicts? And the answer is..
If you are trying to commit one of you changes to origin, but some has already modifies the same branch and that version of change is not on your local branch, then it resist to commit, called “Commit Conflicts”.
User A pull the Origin Repository to the local Repository
Made changes to the branch
Origin branch got change before pushing the “C1” changes to origin.
Now as the local repository is not identical to Origin repository, commit will show the conflicts when you try push.
Pull the change from server (Origin) to local Repository
Now as all the changes from Origin are on Local Repository, we can add one more commit and Push to Origin.
Create a Repository
- Clone to Local Repository url: https://github.com/ashishtheapexian/NEW_DEMO_REPO.git Clone Command: git clone https://github.com/ashishtheapexian/NEW_DEMO_REPO.git
ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/test (master) $ cd .. ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT (20180110) $ git clone https://github.com/ashishtheapexian/NEW_DEMO_REPO.git Cloning into 'NEW_DEMO_REPO'... warning: You appear to have cloned an empty repository. ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT (20180110) $ ls accordian/ awesome-orclapex/ Material-Kanban-Board/ Social_Footer/ APex_ig/ Bamboo/ move_item/ sticky/ apex_oauth/ bootstrap-material-design/ NEW_DEMO_REPO/ StickyNotes/ Apex_Profiler/ cdn-extras/ node-oracledb/ takenote/ apex_textfield_with_buttons/ components/ Oracle-Apex-Solutions/ test/ apex-client-extension/ css3-floating-button/ plsql-md-doc/ test.txt apex-date-range/ Interactive_report/ Pretius-APEX-Enhanced-Lov-Item/ web-desktop/ apex-enhanced-modal-dialog/ lic_utility.sql Render-Region-to-Navigation-menu/ webix-adminapp-demo/ APEX-Floating-Button-Menu/ material-apex/ sec.txt webix-jet/ apex-plugin-timeline/ Material-cards/ 'Smooth row view'/ ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT (20180110)
- Add one file on server:
Here we creating the same scenario of non identical branches on Local and Origin. Currently Zero files are on server.
After adding a file (First.txt).
- Start making change in local Repository
- Jump to directory ( cd NEW_DEMO_REPO)
Stage and commit the file
ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $ git add second.txt warning: LF will be replaced by CRLF in second.txt. The file will have its original line endings in your working directory ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $ git status On branch master No commits yet Changes to be committed: (use "git rm --cached ..." to unstage) new file: second.txt ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $ git commit -m "second file commit" [master (root-commit) 9d3fc8a] second file commit 1 file changed, 1 insertion(+) create mode 100644 second.txt ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $
Here is the error message as the remote contains extra work that you do not have on local.
Now as per the hint: Pull the change from Origin
$ git pull From https://github.com/ashishtheapexian/NEW_DEMO_REPO * branch master -> FETCH_HEAD Merge made by the 'recursive' strategy. first.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 first.txt ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master)
- Push the changes to origin back (It will push the second file as well
ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $ git push Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 501 bytes | 250.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To https://github.com/ashishtheapexian/NEW_DEMO_REPO.git c15d82d..ce7fe36 master -> master ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $
- Files on Server
- Check the commits Here are three commits on server after this resolve. As mentioned in “Origin Push” screenshot.