Month: January 2017

How to delete a file from a repo directly on GitHub – 015

Suppose you have a file that you want to delete*, but don’t want to break out a command line interface to do so. You can delete the file directly from GitHub.com.

Delete this file button

Next you can commit the changes to delete the file to the commit.

Delete Class1.cs commit changes form

*Note that this Delete this file button only removes the file from this commit on this particular branch moving forward. It won’t delete the file in any previous commit history or other branches (until they are merged and only from this commit moving forward).

If you need to permanently delete a file (or even if don’t, you still need to read this doc if you haven’t already), check out GitHub’s documentation on Removing Sensitive Data.

Why no -r delete option (read: why no recursive delete)? The shortest answer is this is how Git works as a Distributed Version Control System. If one or more people have cloned your repo, and if anyone changes their Git repo history, the repos won’t be compatible anymore (there might still be a way but it’s way beyond my skills as of today). And note how I’m saying this is how Git works (instead of “how GitHub works”). This is Git functionality. If you want to read more for possible options, check out the git-scm documentation on rewriting history.

How to create a branch via the GitHub UI without creating a Pull Request – 014

You don’t have to use the command line to create a branch. You can also create a branch directly on GitHub.com. And even though the Create a Pull Request page appears, you can cancel out of it.

Suppose you want to make changes to a readme, but you know you want to make a few iterations on the file before it is final. Or perhaps you want to preview the readme as it will appear to visitors of your repo before it goes “live” on the master (default) branch. Using branches is a great way to store your changes online (where others can still see) that’s separate from the master branch.

First, you’ll click the README.md file in the repo file list.

Clicking readme.md in the repo list

Second, you’ll click the Edit this file button on the far right of the file.

clicking Edit this file on far right side

Next, you’ll make your changes. For my example, I’ll add some content and a link back to MSDN Documentation. (Don’t forget to Preview Changes!)

Lastly, instead of using the defaults to commit directly to the master branch, you can specify to Create a new branch for this commit and then click Propose file change.

Create a new branch for this commit selected

Note in the image above I created a branch called readme-draft, but any branch name will do, including the default name generated (not shown, but it is usually username-patch-1).

The next screen to Open a pull request might feel like it is required, but it is optional. Your branch has already been created.

Open a pull request page

Simply click on Code tab or anywhere else to leave this page. You can always go back and create a pull request later, which we’ll cover.

Pull requests 0 and branches 2

How to view all GitHub keyboard shortcuts – 013

To view all the keyboard shortcuts on GitHub, simply press the question mark key on any GitHub.com page and you’ll see the following image:

Keyboard Shortcuts help window for GitHub.com

Pressing question mark key on any page will show you the shortcuts available, whether they are global (for any page) or for a particular page (e.g. Issues).

And as you’ve figured out by now, the Show All link will show all shortcuts, regardless whether they will work for the page you are currently on, hence why there’s so much whitespace in the image above.

I wanted to share this tip now, so you don’t have to wait for me to discover your favorite shortcut. I’ll go over these more over the upcoming months Smile

How to open a file by typing the file name directly from the GitHub repo page – 012

You may not have noticed before, but each GitHub repo page has a Find file button next to the Clone or download button. It’s amazing how many times I’ve clicked the clone button and never even noticed this Find file button.

Find file button on repo page

The File file button takes you to the File Finder page. For example, in the image below, you’re seeing the files from my UX Masters project TheoryC.

Listing of files in TheoryC repo

And from this screen, you can start typing the name of a file.

But why click a button when you can use a keyboard shortcut?!

GitHub has a great collection of keyboard shortcuts. I’m ramping up on these shortcuts myself, hence this blog series. Let’s start with finding files.

On a repo home page, for example https://github.com/saraford/TheoryC, you can press the letter t to navigate directly to this File Finder page.

Now type the name of the file or folder. e.g. I want to go to the MainViewModel class. So I can just start typing “main”.

File finder only showing files containing main as partial match

Notice how in the previous image all I had to type was “main” and the file finder found three files using partial matching. I didn’t have to specify which folder these files resided in. The search was exhaustive throughout the repo.

To recap, to search for a file via the keyboard, press the letter ‘t’ and then start typing the name of your file. No button clicks required Smile