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".
Scenario
User A pull the Origin Repository to the local Repository
Pull from Server |
Made changes to the branch
C1 Changes to the Branch |
Origin branch got change before pushing the "C1" changes to origin.
Origin Branch Changed |
Now as the local repository is not identical to Origin repository, commit will show the conflicts when you try push.
Commit Conflicts |
Solution
Pull the change from server (Origin) to local Repository
Origin Repository Pull |
Now as all the changes from Origin are on Local Repository, we can add one more commit and Push to Origin.
Repository url: https://github.com/ashishtheapexian/NEW_DEMO_REPO.git
Clone Command: git clone 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) |
Clone Repository |
- 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).
Create file on Server: Scenario |
- Start making change in local Repository
- Jump to directory ( cd NEW_DEMO_REPO)
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 |
- Try to Push the changes
ashish@DESKTOP-LUU8F2R MINGW64 /e/GIT/NEW_DEMO_REPO (master) $ git push To https://github.com/ashishtheapexian/NEW_DEMO_REPO.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/ashishtheapexian/NEW_DEMO_REPO.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 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.
Commits |
No comments:
Post a Comment
Please do not add any spam links or abusive comments.