howto:git
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
howto:git [2021/12/26 10:46] – [Test Scenarios] va7fi | howto:git [2021/12/26 12:26] (current) – [Test Scenarios] va7fi | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Git ====== | ====== Git ====== | ||
===== Test Scenarios ===== | ===== Test Scenarios ===== | ||
+ | Summary: | ||
+ | * When cloning from remote to local or pushing from local to remote, '' | ||
+ | * When pushing local changes to remote, the remote master can't be checkout out. | ||
+ | |||
+ | References: | ||
+ | * [[https:// | ||
+ | * Using [[https:// | ||
+ | | ||
==== Initial Cloning ==== | ==== Initial Cloning ==== | ||
- | Summary: ownership is not preserved. | ||
- | |||
* Create two files in a '' | * Create two files in a '' | ||
* Change their permissions and ownership to match what's on the server:< | * Change their permissions and ownership to match what's on the server:< | ||
~/ | ~/ | ||
- | |||
total 24 | total 24 | ||
-rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file1.txt | -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file1.txt | ||
Line 19: | Line 24: | ||
git commit -m ' | git commit -m ' | ||
git log | git log | ||
- | |||
commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master) | commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master) | ||
Author: Patrick Truchon < | Author: Patrick Truchon < | ||
Line 33: | Line 37: | ||
* The log on the local copy looks good:< | * The log on the local copy looks good:< | ||
~/ | ~/ | ||
- | |||
commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master, origin/ | commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 (HEAD -> master, origin/ | ||
Author: Patrick Truchon < | Author: Patrick Truchon < | ||
Line 41: | Line 44: | ||
</ | </ | ||
- | * But the '' | + | * But the '' |
~/ | ~/ | ||
- | |||
total 24 | total 24 | ||
-rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file1.txt | -rwxrwxr-x 1 ptruchon ptruchon 26 Dec 26 10:24 file1.txt | ||
Line 49: | Line 51: | ||
</ | </ | ||
- | * Change the group back to '' | + | * Change the group back to '' |
- | sudo chgrp www-data * | + | sudo chgrp www-data |
ls -l | ls -l | ||
- | |||
total 24 | total 24 | ||
- | -rwxrwxr-x 1 ptruchon www-data 26 Dec 26 10:24 file1.txt | + | -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file1.txt |
- | -rwxrwxr-x 1 ptruchon www-data 26 Dec 26 10:24 file2.txt | + | -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:24 file2.txt |
</ | </ | ||
+ | |||
==== Making Local Changes ==== | ==== Making Local Changes ==== | ||
* Edit '' | * Edit '' | ||
~/ | ~/ | ||
- | |||
On branch master | On branch master | ||
Your branch is up to date with ' | Your branch is up to date with ' | ||
Line 77: | Line 78: | ||
git commit -m ' | git commit -m ' | ||
git status | git status | ||
- | |||
On branch master | On branch master | ||
Your branch is ahead of ' | Your branch is ahead of ' | ||
Line 85: | Line 85: | ||
git log | git log | ||
- | |||
commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master) | commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master) | ||
Author: Patrick Truchon < | Author: Patrick Truchon < | ||
Line 100: | Line 99: | ||
+ | ==== Push Changes to Remote ==== | ||
+ | * Attempting to push changes to remote while master is still checked out on remote doesn' | ||
+ | ~/ | ||
+ | Enumerating objects: 5, done. | ||
+ | Counting objects: 100% (5/5), done. | ||
+ | Delta compression using up to 4 threads | ||
+ | Compressing objects: 100% (3/3), done. | ||
+ | Writing objects: 100% (3/3), 329 bytes | 329.00 KiB/s, done. | ||
+ | Total 3 (delta 0), reused 0 (delta 0) | ||
+ | remote: error: refusing to update checked out branch: refs/ | ||
+ | remote: error: By default, updating the current branch in a non-bare repository | ||
+ | remote: is denied, because it will make the index and work tree inconsistent | ||
+ | remote: with what you pushed, and will require 'git reset --hard' | ||
+ | remote: the work tree to HEAD. | ||
+ | remote: | ||
+ | remote: You can set the ' | ||
+ | remote: to ' | ||
+ | remote: its current branch; however, this is not recommended unless you | ||
+ | remote: arranged to update its work tree to match what you pushed in some | ||
+ | remote: other way. | ||
+ | remote: | ||
+ | remote: To squelch this message and still keep the default behaviour, set | ||
+ | remote: ' | ||
+ | To / | ||
+ | ! [remote rejected] master -> master (branch is currently checked out) | ||
+ | error: failed to push some refs to '/ | ||
+ | </ | ||
+ | * Workaround is to checkout a temporary branch on remote:< | ||
+ | ~/ | ||
+ | Switched to a new branch ' | ||
+ | </ | ||
+ | |||
+ | * Then push the local changes to remote:< | ||
+ | ~/ | ||
+ | Enumerating objects: 5, done. | ||
+ | Counting objects: 100% (5/5), done. | ||
+ | Delta compression using up to 4 threads | ||
+ | Compressing objects: 100% (3/3), done. | ||
+ | Writing objects: 100% (3/3), 329 bytes | 329.00 KiB/s, done. | ||
+ | Total 3 (delta 0), reused 0 (delta 0) | ||
+ | To / | ||
+ | | ||
+ | </ | ||
+ | |||
+ | * Check status and log from local:< | ||
+ | ~/ | ||
+ | On branch master | ||
+ | Your branch is up to date with ' | ||
+ | |||
+ | nothing to commit, working tree clean | ||
+ | |||
+ | ~/ | ||
+ | commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master, origin/ | ||
+ | Author: Patrick Truchon < | ||
+ | Date: Sun Dec 26 10:45:41 2021 -0800 | ||
+ | |||
+ | changed file1.txt from local | ||
+ | |||
+ | commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 | ||
+ | Author: Patrick Truchon < | ||
+ | Date: Sun Dec 26 10:21:24 2021 -0800 | ||
+ | |||
+ | initial commit on remote | ||
+ | </ | ||
+ | |||
+ | * On remote, checkout master and delete the temporary branch< | ||
+ | ~/ | ||
+ | Switched to branch ' | ||
+ | Deleted branch tmp (was 0e5ccde). | ||
+ | </ | ||
+ | |||
+ | * Status and log both look good:< | ||
+ | git status | ||
+ | On branch master | ||
+ | nothing to commit, working tree clean | ||
+ | |||
+ | git log | ||
+ | commit b7d91058fed9fe64c96525a3d0bef56c682ade68 (HEAD -> master) | ||
+ | Author: Patrick Truchon < | ||
+ | Date: Sun Dec 26 10:45:41 2021 -0800 | ||
+ | |||
+ | changed file1.txt from local | ||
+ | |||
+ | commit 0e5ccdedd1c9188996aadad3a8e2be5a319ab789 | ||
+ | Author: Patrick Truchon < | ||
+ | Date: Sun Dec 26 10:21:24 2021 -0800 | ||
+ | |||
+ | initial commit on remote | ||
+ | </ | ||
+ | |||
+ | * But group ownership of the modified file wasn't preserved< | ||
+ | ~/ | ||
+ | total 24 | ||
+ | -rwxrwxr-x 1 ptruchon ptruchon 50 Dec 26 12:01 file1.txt | ||
+ | -rwxrwx--- 1 ptruchon www-data 26 Dec 26 10:20 file2.txt | ||
+ | </ | ||
howto/git.1640544399.txt.gz · Last modified: 2021/12/26 10:46 by va7fi