git ! [rejected] & Automatic merge failed; fix conflicts and then commit the result
-
git man page: http://bit.ly/2nvGNWB
$ git push origin master To [email protected]:testbeetroot54/mygitrepo.git ! [rejected] master -> master (fetch first) error: failed to push some refs to '[email protected]:testbeetroot54/mygitrepo.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.
Git pretty much explains what is happening, it asking us to pull in the changes from the remote first, before we continue, so we try a git pull
$ git pull origin master remote: Counting objects: 4, done. remote: Compressing objects: 100% (4/4), done. remote: Total 4 (delta 2), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (4/4), done. From github.com:testbeetroot54/mygitrepo * branch master -> FETCH_HEAD c8b9f8e..48b228a master -> origin/master Auto-merging watch/mathup CONFLICT (content): Merge conflict in watch/mathup Automatic merge failed; fix conflicts and then commit the result.
Check git status
$ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: watch/mathup no changes added to commit (use "git add" and/or "git commit -a")
Open your file locally, you will see it's put in some helpful comments to show you where the conflicts are, you need to collaborate with others to see which line to keep, We decide to keep the local copy of the file, and here we'll just keep the first line and delete the second line in out local copy.
#!/bin/bash <<<<<<< HEAD # This is a info for the script it does sq root of a number. ======= # This is a info the script it does sq root of a number. >>>>>>> 48b228a28b5fb83825b274f39890598eac2bb76c [ $# -ne 1 ] && { echo 'Usage: sqrt number' exit 1 } || { echo -e "sqrt($1)\nquit\n" | bc -q -i | head -2 | tail -1 }
So we are left with:
#!/bin/bash # This is a info for the script it does sq root of a number. [ $# -ne 1 ] && { echo 'Usage: sqrt number' exit 1 } || { echo -e "sqrt($1)\nquit\n" | bc -q -i | head -2 | tail -1 }
Add and commit the file locally.
$ git add . $ git commit -m "Fixed conflicts in mathup file" [master 5dde774] Fixed conflicts in mathup file $ git commit -m "Fixed conflicts in mathup file" [master 5dde774] Fixed conflicts in mathup file
Push up the latest changes from you local master to github
$ git push origin master Counting objects: 11, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (5/5), 584 bytes | 0 bytes/s, done. Total 5 (delta 2), reused 0 (delta 0) remote: Resolving deltas: 100% (2/2), completed with 2 local objects. To [email protected]:testbeeroot54/mygitrepo.git 48b228a..5dde774 master -> master
© Lightnetics 2024