From 105dbae4a4ada6ef1b8f1581428f9886a204713a Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Tue, 3 Dec 2013 09:35:59 -0500 Subject: [PATCH 1/3] Incorporating many of the changes recommended by @wking, but still unsure how to discuss the `-u` flag to `git push`. If we create a new repository on GitHub *without* a license or README, GitHub's own instructions are to: touch README.md git init git add README.md git commit -m "first commit" git remote add origin git@github.com:gvwilson/no-initial-files.git git push -u origin master or to: git remote add origin git@github.com:gvwilson/no-initial-files.git git push -u origin master How do we explain (or explain away) the use of `-u` in this case when it isn't needed to clone an existing repository that has files? --- git/novice/01-backup.md | 29 ++++++++++++++++------------- git/novice/02-collab.md | 16 ++++++++-------- git/novice/03-conflict.md | 12 ++++++------ git/novice/04-open.md | 4 ++-- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/git/novice/01-backup.md b/git/novice/01-backup.md index f47728c0f..da8984b73 100644 --- a/git/novice/01-backup.md +++ b/git/novice/01-backup.md @@ -5,7 +5,7 @@ title: A Better Kind of Backup level: novice --- The first time we use Git on a new machine, -we need to run a commands to configure a few things: +we need to configure a few things: ``` $ git config --global user.name "Vlad Dracula" @@ -102,9 +102,9 @@ $ git status nothing added to commit but untracked files present (use "git add" to track) ``` -The message "untracked files" means that there's a file in the directory +The "untracked files" message means that there's a file in the directory that Git isn't keeping track of. -We can tell it that it should like this: +We can tell Git that it should do so like this: ``` $ git add mars.txt @@ -125,7 +125,7 @@ $ git status # ``` -Git now knows that it's supposed to keep tack of this file, +Git now knows that it's supposed to keep track of this file, but it hasn't yet recorded any changes for posterity. To get it to do that, we need to run one more command: @@ -142,6 +142,10 @@ Git takes everything we have told it to save using `git add` and stores a copy permanently inside the special `.git` directory. We use the `-m` flag (for "message") to record a comment that will help us remember later on what we did and why. +If we just run `git commit` without the `-m` option, +Git will launch `nano` (or whatever other editor we configured at the start) +so that we can write a longer message. + If we run `git status` now: ``` @@ -163,8 +167,7 @@ Date: Thu Aug 22 09:51:46 2013 -0400 Starting to think about Mars ``` -Now suppose Dracula adds more information to the file -(remember, `>>` appends rather than overwriting): +Now suppose Dracula adds more information to the file: ``` $ nano mars.txt @@ -210,20 +213,20 @@ index df0654a..315bf3a 100644 +The two moons may be a problem for Wolfman ``` -The output is cryptic because it isn't really intended for human beings to read: -it's a series of commands for tools like editors and `patch` +The output is cryptic because +it is actually a series of commands for tools like editors and `patch` telling them how to reconstruct one file given the other. If we can break it down into pieces: 1. The first line tells us that Git is using the Unix `diff` command to compare the old and new versions of the file. -2. The second line tells exactly which versions of the file it is comparing; - we'll look in a moment at what `df0654a` and `315bf3a` mean. +2. The second line tells exactly which [revisions](../../gloss.html#revision) of the file + Git is comparing; + `df0654a` and `315bf3a` are unique computer-generated labels for those revisions. 3. The remaining lines show us the actual differences and the lines on which they occur. - The numbers between the `@@` markers tell editors which lines we're changing, - and if you look in the left margin below them, - you'll see the line we are adding marked with a '+'. + The numbers between the `@@` markers indicate which lines we're changing; + the `+` on the lines below show that we are adding lines. Let's commit our change: diff --git a/git/novice/02-collab.md b/git/novice/02-collab.md index 401a26216..f70b38d0a 100644 --- a/git/novice/02-collab.md +++ b/git/novice/02-collab.md @@ -7,8 +7,7 @@ level: novice Version control really comes into its own when we begin to collaborate with other people. We already have most of the machinery we need to do this; -the only thing missing is to move files -from one repository to another. +the only thing missing is to copy changes from one repository to another. Systems like Git and Mercurial allow us to move work between any two repositories. In practice, @@ -34,7 +33,7 @@ $ cd planets $ git init ``` -Our local repository still contains the files `mars.txt` that we wrote earlier, +Our local repository still contains our earlier work on `mars.txt`, but the remote repository on GitHub doesn't contain any files yet: FIXME: diagram @@ -48,9 +47,10 @@ the string we need to identify it: FIXME: screenshot For now, -we'll use the 'http' identifier, +we'll use the 'http' [protocol](../../gloss.html#protocol) +(which is also used by web browsers) since it requires the least setup. -Copy that string from the browser, +Copy that URL from the browser, go into the local `planets` repository, and run this command: @@ -80,7 +80,7 @@ Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (9/9), 821 bytes, done. Total 9 (delta 2), reused 0 (delta 0) -To https://github.com/gvwilson/planets +To https://github.com/vlad/planets * [new branch] master -> master Branch master set up to track remote branch master from origin. ``` @@ -141,7 +141,7 @@ Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes, done. Total 3 (delta 0), reused 0 (delta 0) -To https://github.com/gvwilson/planets.git +To https://github.com/vlad/planets.git 9272da5..29aba7c master -> master ``` @@ -163,7 +163,7 @@ remote: Counting objects: 4, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0) Unpacking objects: 100% (3/3), done. -From https://github.com/gvwilson/planets +From https://github.com/vlad/planets * branch master -> FETCH_HEAD Updating 9272da5..29aba7c Fast-forward diff --git a/git/novice/03-conflict.md b/git/novice/03-conflict.md index 86d2d5622..eb901e1c0 100644 --- a/git/novice/03-conflict.md +++ b/git/novice/03-conflict.md @@ -51,7 +51,7 @@ Delta compression using up to 4 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 352 bytes, done. Total 3 (delta 1), reused 0 (delta 0) -To https://github.com/gvwilson/planets +To https://github.com/vlad/planets 29aba7c..dabb4c8 master -> master ``` @@ -87,9 +87,9 @@ but Git won't let us push it to GitHub: ``` $ git push origin master -To https://github.com/gvwilson/planets.git +To https://github.com/vlad/planets.git ! [rejected] master -> master (non-fast-forward) -error: failed to push some refs to 'https://github.com/gvwilson/planets.git' +error: failed to push some refs to 'https://github.com/vlad/planets.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. @@ -109,7 +109,7 @@ remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 3 (delta 1) Unpacking objects: 100% (3/3), done. -From https://github.com/gvwilson/planets +From https://github.com/vlad/planets * branch master -> FETCH_HEAD Auto-merging mars.txt CONFLICT (content): Merge conflict in mars.txt @@ -188,7 +188,7 @@ Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 697 bytes, done. Total 6 (delta 2), reused 0 (delta 0) -To https://github.com/gvwilson/planets.git +To https://github.com/vlad/planets.git dabb4c8..2abf2b1 master -> master ``` @@ -207,7 +207,7 @@ remote: Counting objects: 10, done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 2), reused 6 (delta 2) Unpacking objects: 100% (6/6), done. -From https://github.com/gvwilson/planets +From https://github.com/vlad/planets * branch master -> FETCH_HEAD Updating dabb4c8..2abf2b1 Fast-forward diff --git a/git/novice/04-open.md b/git/novice/04-open.md index f97111419..f598a6e92 100644 --- a/git/novice/04-open.md +++ b/git/novice/04-open.md @@ -225,11 +225,11 @@ not least because it gives them fewer passwords to remember. However, all of these services place some constraints on people's work. In particular, -they give users a choice: +most give users a choice: if they're willing to share their work with others, it will be hosted for free, but if they want privacy, -they have to pay. +they may have to pay. Sharing might seem like the only valid choice for science, but many institutions may not allow researchers to do this, either because they want to protect future patent applications From f6e9ac089569b14799f81d972dc149a9a62a4e39 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Tue, 3 Dec 2013 14:48:30 -0500 Subject: [PATCH 2/3] Adding more edits by @wking --- git/novice/01-backup.md | 2 +- git/novice/reference.md | 8 ++++---- lessons/swc-git/tutorial.md | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/git/novice/01-backup.md b/git/novice/01-backup.md index da8984b73..f4d792f85 100644 --- a/git/novice/01-backup.md +++ b/git/novice/01-backup.md @@ -42,7 +42,7 @@ $ cd planets and tell Git to make it a [repository](../gloss.html#repository): ``` -$ git init . +$ git init ``` If we use `ls` to show the directory's contents, diff --git a/git/novice/reference.md b/git/novice/reference.md index d718d8e27..1f8ef6191 100644 --- a/git/novice/reference.md +++ b/git/novice/reference.md @@ -11,9 +11,9 @@ Set global configuration (only needs to be done once per machine): git config --global color.ui "auto" git config --global core.editor "your_editor" -Initialize a directory as a repository: +Initialize the current working directory as a repository: - git init . + git init Display the status of the repository: @@ -23,9 +23,9 @@ Add specific files to the staging area: git add filename_1 filename_2 -Add all modified files to the staging area: +Add all modified files in the current directory and its sub-directories to the staging area: - git add -A + git add -A . Commit changes in the staging area to the repository's history: (Without `-m` and a message, this command runs a text editor.) diff --git a/lessons/swc-git/tutorial.md b/lessons/swc-git/tutorial.md index 5c8ded00f..32ccb5034 100644 --- a/lessons/swc-git/tutorial.md +++ b/lessons/swc-git/tutorial.md @@ -162,7 +162,7 @@ $ cd planets and tell Git to initialize it: ``` -$ git init . +$ git init ``` If we use `ls` to show the directory's contents, @@ -707,7 +707,7 @@ Let's add and commit those changes (the `-A` flag to `git add` means "add everything"): ``` -$ git add -A +$ git add -A . $ git status # On branch moons # Changes to be committed: From 75a2cf6695602ee3e91e63a422197dec3ceb7166 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Fri, 6 Dec 2013 19:49:12 -0500 Subject: [PATCH 3/3] Explaining away the -u flag --- git/novice/02-collab.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/git/novice/02-collab.md b/git/novice/02-collab.md index f70b38d0a..c24448d34 100644 --- a/git/novice/02-collab.md +++ b/git/novice/02-collab.md @@ -74,7 +74,7 @@ this command will push the changes from our local repository to the repository on GitHub: ``` -$ git push -u origin master +$ git push origin master Counting objects: 9, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. @@ -89,6 +89,13 @@ Our local and remote repositories are now in this state: FIXME: diagram +> ### The '-u' Flag +> +> You may see a `-u` option used with `git push`. +> This tells Git what [branch](../../gloss.html#branch) to use +> in the repository you're pushing to. +> We discuss branches and branching in our intermediate-level lessons. + We can pull changes from the remote repository to the local one as well: ``` @@ -145,11 +152,6 @@ To https://github.com/vlad/planets.git 9272da5..29aba7c master -> master ``` -Notice that we *didn't* use the `-u` flag to `git push`: -the origin repository (the one on GitHub) already knows what `master` means. -We discuss this in a lot more detail in our intermediate lesson -when we talk about branching. - Our three repositories now look like this: FIXME: diagram