Pew Pew Laser Blog

Code. Glass art. Games. Baking. Cats. From Seattle, Washington and various sundry satellite locations.

Blogs about git

Spinning Up a New GitHub Pages Site.

9.11.2017

Pages might just be one of my favorite things about GitHub. Though I often use them for lists of links to go along with my presentations, they are capable of much more complex static sites.

Here is a quick reminder of how to set up a new GitHub Pages site:

  1. Create a new repo on GitHub.
  2. Don't create any new files yet, even licenses or readmes. If you have already created files, then stash them.
  3. Clone that repo locally and check out a new gh-pages branch (git checkout -b gh-pages).
  4. Pop any files you've stashed. Add any other files you want in your repo.
  5. Commit the changes, and then push the gh-pages branch up to Github.

You're done! You can now view your new page at https://[your-user-name].github.io/[your-repo-name]/.

If you have somehow ended up with a master branch with commits, you can remove it thusly:

Git History.

11.2.2016

Want to take a spin in the good old git time machine? Here are some useful ways to do that.

git show --name-only [sha]
Show which files have changed between the referenced [sha] and the current HEAD.
git log --grep=[stuff]
Show any commits where the commit message matches the regular expression [stuff].
git log -p [filename]
Show the log (commits and changes) for a the file [filename]. You can add any log arguments to this, such as 25 for only the most recent entries in the log: git log -p -25 README.md.
git grep [stuff]
Use the power of git to search for any matches of the regular expression [stuff] in the repo.

Piping Output

Git Tips - Diff.

2.22.2016

Let's talk about how to refer to previous commits absolutely using a hash/sha; or relative to your working directory, master, or previous commits.

Here's quick reference on some cool things you can do with Git's diff command:

git diff
The standard form of git diff will show all differences between your current working directory and the index (the files that Git is watching and has staged for your next commit).
git diff --cached
Just the differences that you've staged (files added to the index); what you would be committing if you run "git commit" without "-a" option.
git diff --name-only
Show just the names of files that are different between your working directory and the index (last commit). Or, pass in two hashes to compare files from those two commits.
git diff master --name-only
Show all files changed between master and your current working directory. This is great for reviewing what changed files you're actually going to commit.
git diff HEAD
Both staged and unstaged changes in your repo; what you would be committing if you run git commit -all.
git diff HEAD~1
Compare current files to the ones from the previous commit. Also git diff HEAD^ HEAD.
git diff HEAD master [file]
Show differences between the working directory and master for one file.
git diff [hash]
Diff between current and previous commit.

Note that hash is that long string which identifies a commit if you do git log.

Git Diff.

1.23.2014

Here are some useful git diff commands:

git diff --name-only
Show names of files that are different between the index (your watched files) and your last commit. Or, pass in two hashes to compare files from those two hashes.
git diff master --name-only
Show all files changed between master and your current working directory. This is great for reviewing changes you'll be making when you merge to master.
git show --name-only [sha]
Show the commit log, and which files have changed in a given hash.
git diff master [filename]
Show the differences between the working directory and master for the file specified.

Git Tips - Commits and History.

11.12.2013

Here are a few things for working with commits and previous file versions.

git add -A git revert [sha]
The above block is 2 sequential git commands. First, add all file changes to Git's watchlist. Roll back to the previous commit, throwing away all changes that you haven't yet committed.
git checkout -b [branch-name] [sha]
Check out an old commit to a new branch so that you can fiddle with it.
git checkout origin/master -- [file]
Replace the current working directory version of that file with the one from master. This is great for reverting a bunch of changes.
git add -A git stash
These two commands which will allow you to save your work in the middle of a commit, and come back to it later. In detail:
  1. Save all changed, added and deleted files to the index
  2. Save that work into a magic "stash".
Now you can do whatever you need to do next, such as checkout another branch or switch projects. When you're ready to come back to your stashed work: git stash pop
git stash list
List all of the stuff you've previously stashed.
git stash apply --index
Applies your most recently stashed work back to your working index. You must also git stash drop [stash name] to remove that particular stash from the list of stashed stuff. git stash pop as used above just handles all of this for you.

More blogs about git: