Git: Difference between revisions
From charlesreid1
No edit summary |
No edit summary |
||
| Line 13: | Line 13: | ||
<pre> | <pre> | ||
git remote set-url origin git@github.com:user/repo.git | git remote set-url origin git@github.com:user/repo.git | ||
</pre> | |||
=Scenarios= | |||
==Git Conflict== | |||
Sometimes, when you try and push your commits with <code>git push</code>, you'll see a message like this: | |||
<pre> | |||
$ git push | |||
To https://github.com/siluria/transport.git | |||
Merge branch 'master' of https://github.com/siluria/transport | |||
! [rejected] master -> master (fetch first) | |||
error: failed to push some refs to 'https://github.com/siluria/transport.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 merge the remote changes (e.g., | |||
hint: 'git pull') before pushing again. | |||
hint: See the 'Note about fast-forwards' in 'git push --help' for details. | |||
</pre> | |||
Then, if you try and pull the latest changes with <code>git pull</code>, you might see a message like this: | |||
<pre> | |||
$ git pull | |||
remote: Counting objects: 8, done. | |||
remote: Compressing objects: 100% (8/8), done. | |||
remote: Total 8 (delta 0), reused 2 (delta 0) | |||
Unpacking objects: 100% (8/8), done. | |||
From https://github.com/siluria/transport | |||
153782f..10e0b68 master -> origin/master | |||
Auto-merging twodomain/SubdomainCatalyst.py | |||
Auto-merging twodomain/Interface.py | |||
Auto-merging twodomain/Driver.py | |||
CONFLICT (content): Merge conflict in twodomain/Driver.py | |||
Automatic merge failed; fix conflicts and then commit the result. | |||
</pre> | |||
In this case, you can edit the file with the conflict, in this case, <code>Driver.py</code>. You'll see some lines like this: | |||
<pre> | |||
<<<<<<< HEAD | |||
old code | |||
======= | |||
new code | |||
>>>>>>> iss53 | |||
</pre> | |||
Edit this file to merge the code however you decide. Once you do that, you'll run <code>git add</code> on the code with the file, which tells git you have resolved the conflict. | |||
<pre> | |||
$ git add Driver.py | |||
</pre> | |||
Then - this is key - you run <code>git commit</code> with NO OTHER ARGUMENTS. | |||
If you try and add arguments, i.e., specifying which file to commit, or adding a commit message, you'll see an error like this: | |||
<pre> | |||
$ git commit Driver.py -m 'resolving conflict.' | |||
fatal: cannot do a partial commit during a merge. | |||
</pre> | |||
Just run <code>git commit</code> with no arguments: | |||
<pre> | |||
$ git commit | |||
[master d1d98ed] Merge branch 'master' of https://github.com/siluria/transport | |||
</pre> | |||
Now you should be able to run <code>git push</code> with no problems: | |||
<pre> | |||
$ git push | |||
Counting objects: 23, done. | |||
Delta compression using up to 8 threads. | |||
Compressing objects: 100% (12/12), done. | |||
Writing objects: 100% (12/12), 1.48 KiB | 0 bytes/s, done. | |||
Total 12 (delta 10), reused 0 (delta 0) | |||
To https://github.com/siluria/transport.git | |||
10e0b68..d1d98ed master -> master | |||
</pre> | </pre> | ||
Revision as of 17:45, 27 August 2014
Routine Git Operations
Stop Github Asking for Username and Password
Step 1: Set up Github SSH Keys
https://help.github.com/articles/generating-ssh-keys
Step 2: Switch Repos from HTTPS to SSH
http://stackoverflow.com/questions/10126381/why-does-github-keep-asking-me-for-repo-credentials
git remote set-url origin git@github.com:user/repo.git
Scenarios
Git Conflict
Sometimes, when you try and push your commits with git push, you'll see a message like this:
$ git push To https://github.com/siluria/transport.git Merge branch 'master' of https://github.com/siluria/transport ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/siluria/transport.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 merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Then, if you try and pull the latest changes with git pull, you might see a message like this:
$ git pull remote: Counting objects: 8, done. remote: Compressing objects: 100% (8/8), done. remote: Total 8 (delta 0), reused 2 (delta 0) Unpacking objects: 100% (8/8), done. From https://github.com/siluria/transport 153782f..10e0b68 master -> origin/master Auto-merging twodomain/SubdomainCatalyst.py Auto-merging twodomain/Interface.py Auto-merging twodomain/Driver.py CONFLICT (content): Merge conflict in twodomain/Driver.py Automatic merge failed; fix conflicts and then commit the result.
In this case, you can edit the file with the conflict, in this case, Driver.py. You'll see some lines like this:
<<<<<<< HEAD old code ======= new code >>>>>>> iss53
Edit this file to merge the code however you decide. Once you do that, you'll run git add on the code with the file, which tells git you have resolved the conflict.
$ git add Driver.py
Then - this is key - you run git commit with NO OTHER ARGUMENTS.
If you try and add arguments, i.e., specifying which file to commit, or adding a commit message, you'll see an error like this:
$ git commit Driver.py -m 'resolving conflict.' fatal: cannot do a partial commit during a merge.
Just run git commit with no arguments:
$ git commit [master d1d98ed] Merge branch 'master' of https://github.com/siluria/transport
Now you should be able to run git push with no problems:
$ git push Counting objects: 23, done. Delta compression using up to 8 threads. Compressing objects: 100% (12/12), done. Writing objects: 100% (12/12), 1.48 KiB | 0 bytes/s, done. Total 12 (delta 10), reused 0 (delta 0) To https://github.com/siluria/transport.git 10e0b68..d1d98ed master -> master