Skip to content

Instantly share code, notes, and snippets.

@mixelpixel
Last active April 5, 2019 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mixelpixel/6e69151d7117351ca4677fa36f6478b4 to your computer and use it in GitHub Desktop.
Save mixelpixel/6e69151d7117351ca4677fa36f6478b4 to your computer and use it in GitHub Desktop.
Helping students with their computer, text editor, Git, and GitHub

Helping students with their computer, text editor, Git, and GitHub

  • What is Git?
  • What is RAM?
  • What is SSD/Hard drive?
  • What are "invisible files"?
  • Where are the Git resource files?
  • Is my development environment configured for pushing Git commits?
  • How is GitHub different than Git?

Git

Prior to resolving or introducing intermediate and advanced Git commands or techniques, we can verify that students are first grounded in their understanding of what Git is doing.

  1. Does the student understand how their computer memory (RAM) and their computer's internal storage work with their text editor? I.e. the files they are writing to get stored on their drive. As they make changes, the changes are stored in their computer's RAM until they are saved to the file on the computer drive.

What does a Git project add to this?

  1. Is the student aware of how to initialize a Git project with git init? Do they know that there is a .git directory in their Git project where Git stores the it's project resource files? Note that files and folders which start with a dot are by default "invisible" through the Finder, Explorer or Nautilus depending upon their operating system.
  • use terminal commands like ls -al or DIR to display the "invisible" files and folders.
  • Also, with macOS, in the Finder you can use cmd+shift+. to toggle viewing "invisible" files and folders.
  1. At the very least, a Git project - i.e. any directory containing or initialized with a .git resource folder - can be used to track the history of changes made to the text files within the directory. This will not automagically track every change which goes to and from RAM, and to and from the computer drive. This is where git commit enters the picture. You control the set of changes which the Git Project tracks through commits.
  2. The most fundamental commands with Git are:
  • git log to display the history of commits made to the Git project.

  • git status to display the current state of the Git project. It is a best practice while learning Git to use this command after every other command to verify the state of the Git repository.

  • git add {filename} to stage either an untracked file, or a tracked file which has been modified since the last commit.

    1. git add . and git add --all are also available to stage multiple files at once.
  • git commit to commit the staged files to the history of changes made in the repository.

    1. Note that using git commit without further flags may invoke the default text editor which Git uses. This will often be the Vim text editor. Vim is a modal based editor. Upon Vim being launched, press i to enter the text editing "-- INSERT --" mode. Look for this status in the lower left of the console where Vim has been invoked. Type a commit message. To exit the Vim text editor, press the escape key. This will put Vim in the command entry mode. Then if you entered your commit message through vim, type :wq to write the text file and quit. If you just want to quit without saving a commit messgae, hit escape, type :q and hit enter to exit Vim.
    2. Commit titles can be entered directly through the commit command with the -m flag. For example, git commit -m 'title'. You can also add a more detailed body with a second -m flag. For example, git commit -m 'succinct title' -m 'detailed body of notes about features...'. A second way to enter a more detailed body is to use a single -m flag and put two new lines in between the title and body. For example, before you finish that
    $ git commit -m 'message with a closing quotation mark
    
    You can hit enter twice to put a new line in between your commit title and a body!
    - you can add bullet points
    - explain in detail
    - what you did
    - and this helps your teammates
    - and improves your own analysis
    - best of all, after you've left the project for awhile
    - these comments will help you reorient to your work!
    - So don't forget that closing quotation mark :slightly-smiling-face:'

NOTE: Visual Studio Code's integrated Git tools allow the option of adding Git commit message bodies, and the Atom text editor has an excellent graphical interface for git log, status, add, commit, push and pull. I strongly recommend, however, that students learn the console commands prior to using the integrated toolsets, or GUI's such as Desktop or Tower. That is just my personal opinion though, and so long as the students understand what they are doing with the commands, however they see fit is awesome.

GitHub

Forking a Project

  1. Remember to fork before cloning. As a student at Lambda School, you won't have write access to the Lambda School repositories. You will need to make your own fork of the project so that you can push your commits to your fork.
  1. Making your own fork will allow you to make a "Pull Request" to the Lambda School repository, i.e. a request for someone at Lambda School to evaluate your work and, if we were working on a deployed app, to "pull it in" to the Lambda School repository.
  1. Use git remote -v to confirm the remote url for the origin of the project, i.e. confirm that forked before you cloned. You should see:
https://github.com/{YOUR_GITHUB_HANDLE}/...

...and not:

https://github.com/LambdaSchool/...

Cloning a Project

  1. git clone {remote repository URL}
  2. cd into the project and start working using the tools above.

Pushing to a cloned GitHub repository

  1. git push origin master
  • git is the command
  • push is the Git "method"
  • origin is an alias for a remote repositories URL. This is simply an arbitrary name - a convention. It does not describe the remote URL in terms of any kind of primacy, e.g. as a "source of original content." If you cloned a repository, it is the convention to describe the cloned repositories "origin".
    1. use git remote -v to display which remote url alias are available to the project.
  • master also, merely a convention for naming the particular branch of the project you are referring to when pushing commits to the remote repository.

Finding Pull Requests by author and commenter

  1. From the Lambda School repository, select the "Pull requests" tab.
  2. In the text entry box for "Filters":
  • author:{github_handle} will filter out only PRs authored by that particular GitHub username
  • commenter:{github_handle} will filter out only PRs with comments made by that particular GitHub username
  1. To see all Pull Request from a particular author, us the global Pull Request search feature, e.g. - https://github.com/pulls?utf8=%E2%9C%93&q=author%3Amixelpixel

Git Branches

  1. Until competency with the above is demonstrated, I suggest avoiding branches. They are mission critical tools in the workforce, but can become troublesome without a grounding in the fundamentals of adding a Git workflow to text editing.
  2. git branch will display the branches available in a project.
  3. git branch {name} will create a branch with the {name} used.
  4. git checkout {name} will switch the Git repository to the branch {name}.
  5. git checkout -b {name} will create a new branch with the {name} you choose, and switch the Git repository to that branch.

NOTE: Before switching branches, save the local files and commit them to the working branch. This will prevent work from getting saved to the wrong branch or loss of work.

Git Configuration

First, let’s verify that your global settings for Git are configured to the email and username which you’ve used to sign up with GitHub. The following two commands should return your username and e-mail: git config --global user.name and git config --global user.email

If so, you are good to go! If, however, they return nothing, then you’ll need to use the following commands to configure Git so the commits you push to GitHub properly reflect you as the author. For example, with the username “lisalovescode” and the e-mail “lisa1234@gmail.com

$ git config --global user.name "lisalovescode"
$ git config --global user.email "lisa1234@gmail.com"

See also:

  1. https://help.github.com/articles/setting-your-username-in-git/
  2. https://help.github.com/articles/setting-your-commit-email-address-in-git/
  3. If you do not want your e-mail address published with your commits, GitHub has a couple extra steps for you: https://help.github.com/articles/about-commit-email-addresses/
  4. in the #git channel: https://lambdaschoolstudents.slack.com/archives/C5Z8BMX6K/p1529526794000049
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment