Saturday September 21, 2019

Quick survey on what’s coming:

  1. Why I find GitHub appealing?
  2. Nomenclature confusion.
  3. What finally convinced me?
  4. How to easily use GitHub on Windows?

Why I find GitHub appealing?

It all began with Handy News Reader - an Android app which development I am involved since late 2017. The developer highly recommended GitHub as the destination place for sharing new ideas, reporting bugs, etc. Besides, it was also the right place to grab any new release of the app - even before it landed on Google Play/F-Droid.

But I myself am not a developer, I rarely consider myself a programmer even - so the whole GitHub thing (first impression) seemed to me pretty... weird and alien. I was intrigued, however, why it gained so much praise and interest, and how does it really work, what so special about it?

What was especially intriguing was the time I heard about (even weirder?) thing called “Git”, and learned (kind of) that it has some connections with a command-line-type of a workflow, which I’ve already known how powerful it can be (out of my earlier GNU/Linux experience, when I was totally amazed by the possibilities of such an inconspicuously looking thing like terminal/shell themselves).

Nomenclature confusion.

First I felt confused by terms like “terminal”, “shell”, “command prompt/command line”, “Bash/PowerShell”, and so on - because all of them seemed to be associated with the same single thing. Here, however, it has been fantastically explained and I hope that now I have better comprehension of the matter, which boils down to this (at least to my understanding):

Command line/command prompt.

This means a sole way of interacting with a computer, in which You enter some text commands and then computer replies.

Shell.

This is a program which runs in background and allows to use other programs of Your liking.

Bash/PowerShell.

Those are just examples of shells: Bash is widely known throughout GNU/Linux world, PowerShell stands for its Windows counterpart.

Terminal.

This is a program which provides a command-line “graphic” interface for a shell (so terminal is responsible mainly for how Your text commands will look like visually on the screen - while shell is responsible for how all of those commands will be performed).


The most impressive I found the way You could grab and install new apps under GNU/Linux: there were no need to google Your desired app’s homepage, no need to download its installation file, and no need to go through several windows to finally install it. Instead, You could literally enter a simple single command within terminal, confirm it and voilà (!) - it was all it has been needed to make the magic happen (!!!). “It” somehow knew out of where to grab the app and how to install it on Your PC without bothering You (or at least minimizing this to a high degree). Moreover, You could gather multiple apps in one longer - but still single - command, and, therefore, to delegate their installation at once. It was so amazing that I hardly believed it ;) .

Soon I learned that there are many more things You could do much simpler and faster just via inconspicuous text commands. I even harnessed AutoHotkey under Windows 7 to improve my workflow in similar spirit (i.e., replacing frequently performed actions by a set of commands, or even better: a keyboard shortcut to initiate all of them at once, without a need to enter anything).

Back to Git(Hub), I learned that the whole thing may not be only useful, but also can be operated through the same super-fast-and-easy-command-line-driven-way :) . It means that You don’t have to log-in into Your GitHub account every time You need to use it - You don’t even have to open Your web browser (!). All You need is a couple of simple commands to enter into a terminal window and confirm - that’s all: You have the same result, but much more simpler and quicker (which still amazes me).

What finally convinced me?

As I mentioned before, I'm not consider myself as a “full-blown programmer” or a developer. Nevertheless, as soon as I became aware of GitHub potential and especially, that it’s universal and may be applied to many different things as well as to the programming itself - I’ve found that it could significantly come in handy when it comes to my vocabulary projects (two sets of vocabulary: one which consists of English idioms for Polish students - and the other which consists of Polish ‘extended’ vocabulary for Polish people themselves).

I systematically update both collections (adding new items, improving the existing ones) - official releases are published every three months, but in practice I do the updates locally every couple of days (about once a week). GitHub might be great, I thought, to track those updates and allow each interested person to grab “the newest and hottest” version :) . So I’ve decided to switch from archive.org to the GitHub itself, to host my, so-called, Anki decks (Anki is a fantastic Android/iOS/Windows/GNU/Linux app to learn anything by heart).

I’ve already mentioned a GitHub-related little concern: that at first glance it seems to be clearly dedicated for software developers - so I hadn’t been sure that it is 100% fine to harness it in this new unconventional way to host anything other than programming code. The other day I’ve stumbled upon a fantastic article on GitHub for novel writers (!) - which has totally cleared the picture, providing the information that GitHub itself encourages users to benefit from the platform many other - i.e., non-programming - ways. Furthermore, this theme takes place for years now (read this very interesting article, which tells a lot about many other ways of incorporating GitHub into Your Own workflow/creation, making life easier and widening possibilities). So now I’ve gained more certainty that my particular case is not unique, but even welcomed :) . This finally convinced me to take first steps into the Git, GitHub and all the necessary stuff (for Windows users), which I describe below.

How to easily use GitHub on Windows?

To use GitHub the super-easy-fast-and-‘magical’ way powered by command line under Windows, You need to install two things: Git and Cygwin.

I. Install Git.

You may consider Git as “the engine” or “the core” on top of which GitHub has been designed. It’s Git that is responsible for tracking Your work development and managing team cooperation (if such one exists). Interestingly enough You could stick with Git and totally do without GitHub, still having the whole multiple version tracking feature at hand. You may find GitHub useful when it comes to working on different devices/locations and keeping Your project always up-to-date - all of that without a need of establishing online access to Your project by Yourself (moreover, GitHub provides You with a whole web interface to manage many Git-related things out of the box). In many ways using GitHub resembles syncing files through the cloud (like Google Drive, for example) - the main difference is that, on top of syncing, You have a dedicated dashboard (in a form of a website) which 1) nicely visualizes Your Git(Hub) usage (whether You work alone or in a team, You gain a pretty clear picture of its growth, including potential alternatives for some of its components) and 2) allows You to perform Git-related actions by clicking ‘here and there’ instead of typing commands.

II. Install Cygwin.

Although Windows already has its own terminal and shell, it doesn’t support Git-related commands necessary to use it. Fortunately, You can fix this by installing Cygwin and performing a simple operation, thanks to which Windows suddenly will become more “in the know” (as far as GNU/Linux commands are concerned) ;) . Without diving into technical details, let’s install the thing and perform the magic :) !

Installation process is simple: although there are plenty of custom options to choose - You can simply go through most of them not changing anything. This article will lead You through the installation process step-by-step.

III. Enrich Windows command prompt with GNU/Linux commands.

Once You’ve installed Cygwin You can move to the most interesting part which will make Windows classic command prompt smarter. One way You may notice the difference is to try some GNU/Linux command before and after You perform the procedure. Open the command prompt and type pwd, then confirm. Currently Windows should not understand it (You can learn more about Cygwin commands here). Close the terminal window and do the following:

  1. Open Your system properties with Win+Pause/Break keyboard shortcut.
  2. In the left column click on Advanced system settings.
  3. From the Advanced tab, click on Environment variables at the bottom.
  4. Then in the system variables, locate the path variable and click edit.
  5. At the end of the variable value option, add the following (if You installed everything by default, it should look this way):

;C:\Cygwin\bin

Make sure you add a semicolon to separate it from the other values.

  1. Confirm by OK.

Now You can check out if everything works right, using the same pwd command as before: open the terminal and try again - now, instead of an error message, as a result You should see Your current directory written on the screen.

IV. [optional] Prepare the command prompt.

I’d like to present You two ways of making things easier when it comes to working with the terminal. They are not necessary to incorporate - but You may find them worth Your attention.

Enable copy&paste on Windows <10.

Instead of carefully typing each command You might prefer to simply copy&paste it directly into the terminal window. But if You use Windows 7, You may be surprised that classic Ctrl+V keyboard shortcut does not work. Instead, You can either right click within terminal window and choose Paste - or enable QuickEdit Mode and simply right click each time You want to paste something (to enable this feature: right-click on the window’s title bar › Properties › the Options tab › check the QuickEdit Mode option under Edit Options › confirm by OK.).

Start the terminal directly within Your project folder.

By default, whenever You open terminal window, it starts within the default directory C:\Users\Your user name here, so You need to navigate to Your project directory every time You want to apply some Git action to it. This navigating may often require a couple of additional steps which You could skip if You make the terminal starting automatically within Your project directory.

To do so:

  1. Right click on Your Windows desktop and choose New › Shortcut.
  2. Fill the empty field with cmd.exe and click Next.
  3. Enter the name You’d like for Your custom terminal shortcut. A good idea may be to choose a name which is related to Your project.
  4. Confirm by Finish/Done.
  5. Right click the shortcut You’ve just created and choose Properties (or simply select it and use Alt+Enter).
  6. Fill the Begin with field with Your project directory.
  7. Confirm by Apply and OK buttons.

Now, launch Your terminal shortcut to find out if it really starts withing Your project folder.

V. Identify Yourself.

Git requires to set up Your user name and e-mail address. You can use any user name, but when it comes to email address - if You use GitHub, You should use the same email as You have set up within Your GitHub profile settings (Settings › Emails › Primary email address). If You want to make Your email address private, check Keep my email addresses private within settings section mentioned above. Then take a closer look on this option’s description, it should be something like that:

“We’ll remove your public profile email and use 26142231+YourUserName@users.noreply.github.com when performing (...).”

Note that email address from Your GitHub settings page to further use within Git itself.

Another thing: still within the same settings section uncheck Block command line pushes that expose my email - this step may be necessary to use Git via command line.

Now let’s open Windows command prompt and type (or copy&paste):

git config --global user.email "Your email address here"

Confirm it and then:

git config --global user.name "Your user name here"

After You confirm those steps, You don’t need to repeat them anymore - regardless of how many new projects You will add to Git. If You, however, would like to change Your user name, for example - You can do it at any given moment via the same command mentioned above.

VI. Activate Git within desired folders.

Now, having all the pieces up and running, You can make Git working for Your project. In order to do so:

  1. Open terminal (if You’ve created - described in part IV - custom terminal shortcut specifically related to Your project, use it now).
  2. If You haven’t created custom terminal shortcut - navigate to Your project directory (using cd command - e.g., cd folder1/folder2/etc.; to change drives just type d: (in case of D drive) and confirm).
  3. Enter this command:
    git init

VII. Connect with GitHub.

Now You need “to mirror” Your project directory onto GitHub. If You don’t have a GitHub account yet - now it’s a good time to create one. Once You have it done, create a new repository (a + icon on the top right) - which will be Your project’s mirror. While setting it up, uncheck “Initialize this repository with a README” - it will make further steps easier.

Take a closer look on the specific address with which You’ll be provided during Your repo creation: it should look like that:

https://github.com/YourUserName/YourRepoName.git

Note or copy this address. Now, open the terminal, navigate to Your project folder (or simply use Your custom terminal shortcut) and perform the following command:

git remote add origin https://github.com/YourUserName/YourRepoName.git

VIII. Gain a routine.

Once You have everything set up, You can incorporate it into Your workflow. Each time You’d like to “snapshot” Your work current state, You may use those commands:

  1. [optional] git pull https://github.com/YourUserName/YourRepoName.git
    » which means: download Your project data from the GitHub. This command may come in handy when You’d like to continue working on Your project using other device, so You need all things to be up-to-date. In such a case: first, perform the instruction below from step 1 to 3, then - on the other machine - add this extra 0 step :) .

  2. git add .
    » which means: prepare an update which consists of all the changes within Your project directory (remember a space and a period at the end).

If You want to include only selected files, You can do that as in the following example:

git add file1.txt file2.txt etc.txt

  1. git commit -m "Your comment here."
    » which means: save the update (locally, i.e., only on Your computer) alongside with Your comment (this comment should describe Your update as a whole - there is no way to comment each and every file within the update separately).

Often it is a good idea to comment updates the way which could be understandable for You months (or years?) from now.

  1. git push -u origin master
    » which means: upload the update to the GitHub.

In this step use -u only one time to establish a bond between a remote and local repository - every next time You can do without it.

An example of Git session.

Now, in case You’ve uploaded more than one file at once, if You take a look on Your GitHub repository page (https://github.com/YourUserName/ProjectName), You’ll notice that each of the uploaded files is accompanied by the same comment message You’ve provided while committing. The reason is that comment messages included within git commit -m command relate to the update as a whole - not to the particular files which it consists of. You can gain much clearer picture, however, if You enter the x commits bookmark (x = the current number of Your commits).

Filed in: /3/ | /37/ | /37/ | /63/ | /5/ | /37/ | /3/ | /3/

Your (nick)name:

Your e-mail:

Have a website?

Your message:

remember data for further comments?