Intro to Git and GitHub Part 1: Your first repository

This is a continuation of a tutorial blog series to learn the basics of Git, using GitHub and the GitHub client.

To start from the beginning, go here.

Create a new local repository

First, start up your GitHub client you downloaded in part 0.

To create a new local repository, click the “+” icon in the top left corner of the program.

NewRepo01

Here you’ll be given the option to create or clone a new repo, set the name, path, and default git ignore.

NewRepo02

It doesn’t matter what you name it, remember where you save it though! As for the Git ignore, the default “Windows” setting will be good enough for now. We’ll talk more about that later.

Hit the checkbox when you’re ready. Congrats, you just created your first repository!

Overview

Here is a basic overview/reference of the GitHub client.

NewRepo03

  1. Create or clone a new repository
  2. Currently open repositories
  3. Current branch
  4. Publish/Sync repository to GitHub.
  5. Settings
  6. Commit message/submit for latest changes
  7. Past commits for current branch
  8. Latest changes

Your first commit

Go to the folder you just created your repository in. You can get there easily by clicking on the settings gear in the upper right corner and clicking “Open in Explorer”

You should now be in your new, empty repository. You’ll notice some files have been automatically created. Specifically, a .git folder and a .gitattributes file.

The .git folder has all the information and settings for your repository, you should never mess with this folder unless you know exactly what you’re doing

The .gitattributes file was automatically created for us by GitHub when we chose “Windows” as our settings. It tells Git how to handle certain files. For now, we can ignore it.

Let’s try adding something to your new repository. Right click and hit New->Text Document to create a .txt file.

Now rename this file to README.md

Why README.md? .md is a “Markdown” type format. It’s a simple way of formatting text. A file called “README.md” will later automatically be shown on your GitHub project page.

You can then open up README.md in your text editor of choice. Notepad will work nicely for our purposes.

In classic programmer fashion, let’s write the famous first output:

Hello World!

Save the file, close your text editor, and open your GitHub client back up.

On the right, you should see our new README.md file. If you like, you can hit the little arrow and see the contents of the file that have changed. So far it’s just our “Hello world!” line.

Now we’re going to commit our first changes. Be sure to write a descriptive commit message! You will thank yourself later as you’re trying to figure out what you did during each commit in the future, so it’s good to get in the habit now. I wrote:

Summary:

First Commit

Description:

Added readme file and .gitattributes

 

NewRepo04Hit the checkmark to make your first commit. You should see the commit appear in your history. Your changes have been saved!

Change something!

Now let’s get to the part to show why Git is useful. Go back to your folder (Settings->Open in Explorer) and open back up your README.md file.

Add a new line:

Hello World!

This is my first time using Git!

Save the file and close your text editor again. Now switch back to your GitHub Client. You’ll see that it noticed right away the file has been changed.

It doesn’t just track if the file has been modified, but also exactly how it’s been changed. If you click the arrow to expand, you’ll see it shows that line 1 did not change, but line 2 and 3 did.

NewRepo05Write a new commit message and submit. You now have a saved the changes to  README.md.

Breaking up changes into multiple commits

What if you changed a lot of different things, but didn’t necessarily want to save all those changes at once?

Let’s create three new files. NewFile1.txt, NewFile2.txt, and NewFile3.txt. Doesn’t matter the contents, we’re just making up files for this example.

If you go back to your GitHub client, you’ll notice checkboxes next to each of the names of the new or changed files. To not include a change, simply uncheck the box.

NewRepo06Let’s say we still have more work to do on NewFile2.txt before we want to commit to the changes, but we want to save our work in NewFile1.txt and NewFile3.txt.

Make sure the checkboxes next to NewFile1.txt and NewFile3.txt and checked, and uncheck the one next to NewFile2.txt. Then commit!

NewRepo07Don’t worry, changes to NewFile2.txt aren’t lost. Your folder is still just how it was before, but the changes to NewFile1.txt and NewFile3.txt are now saved. You can then commit NewFile2.txt in a later update.

Discard changes

What if you are working on your program, and you mess something up. How do you undo your latest changes? Maybe you were working on that NewFile2.txt and decided that it wasn’t a great feature after all.

Simply right click the file, and hit “Discard Changes”

NewRepo08


WARNING – There is no recovery for unsaved changes. Make sure you really want to discard all the changes since the last version!


Since NewFile2.txt was a new file, discarding the changes deletes it from your project folder.

Renaming and deleting files

Git automatically monitors all changes to files being tracked.

For example, let’s try renaming NewFile3.txt to NewFile2.txt, now that the original NewFile2.txt file was deleted in the last step.

After doing so, your GitHub client should look like this:

NewRepo09If you delete a file, a “delete” change will appear in the commit changes panel. However, if you rename, sometimes it thinks that one file has been deleted and a new one added.

If you want, you can rename files through the Git shell instead, but in many cases it’s probably just as easy to track the rename as two changes. One new file, and one deleted file.

Reverting changes

What if you wanted to undo a change after you’ve already committed?

Simple! In your GitHub client, go to the commit in question you would like to revert back. For example, let’s undo that first change we made to our README.md file.

NewRepo10Clicking the “Revert” button will undo all the changes done in this commit.

In the GitHub client, this will create a new commit that undoes those changes.

NewRepo11GitHub’s client automatically fills out the message message for the reverse change. Now if you go back to your folder, you’ll see that README.md only has one line!


NOTE: You may need to close and reopen the file in your text editor in order to see the changes.


Ignoring files

What if you had files that you didn’t want to track?

Let’s say our compiler generates a Build.log file. We don’t need to track the state of this, or any .log file within our project.

When you right click the file, you are given a couple options:

NewRepo12If you just want to ignore this specific file for whatever reason, you can click the “Ignore file” option and do so.

If you want to ignore ALL files with the extension .log (or whatever type the currently selected file happens to be), click the second option.


NOTE: Files already tracked/committed will still be tracked. But all future files with that extension will no longer appear in the GitHub client.


This will automatically generate a .gitignore file if you do not have one already. Remember when we automatically added the “Windows” one at the beginning? This is that file.

A .gitignore file lists all the files and extension types Git should ignore when looking for changes.

NewRepo13Remember to commit your new .gitignore file to make sure others who download your project will also have .log extensions ignored!

If you would like to add a premade .gitignore file designed for whatever kind of project you are working on, GitHub provides a repository of commonly used project types.

Visit https://github.com/github/gitignore to see the full list. Download or copy/paste the option you want into your own project file. Remember, you may need to change the file name needs to be “.gitignore” in order to work.

End of Part 1

Click here to return to the main blog post. Part 2 will be posted on Friday.

-Tobiah

Intro to Git and GitHub

This tutorial will teach you the basics of Git, using GitHub and the GitHub client.

Experience required:

None. This is written for people who have never used any kind of version control system before.

What will you learn:

Octocat
Part 0: Introduction and Setup

  • What is Git
  • Why use version control?
  • What is GitHub?
  • Setting up the GitHub client

Part 1: Your first repository

  • Creating a new local repository
  • Committing changes
  • Discarding changes
  • Renaming an deleting files
  • Reverting changes
  • Ignoring files

Part 2: Publishing, cloning, and forking using the GitHub client.

  • Publish a new repository
  • Push changes
  • Clone an existing repository
  • Fork an existing repository
  • Pull requests

Part 3: Introduction to Branching.

  • What is branching?
  • Create a branch
  • Switch between branches
  • Deleting branch

Part 4: Merging and Rebasing overview.

  • Merging branches
  • Resolving conflicts
  • Undoing a merge
  • Rebasing
  • When should you merge and when should you rebase?

Each part will be a different post. For now, let’s dive into part 0.

Part 0: Introduction and Setup

What is Git?

Git is a distributed revision control system created by Linus Torvalds.

Since its creation in 2005, Git has quickly become one of the most widely used version control and source code management systems.

Why use version control?

Have you ever accidentally deleted an important file? Had a computer crash and lost work?

Do you manually zip and/or copy/paste your important files to keep backups?

Have you ever tried changing something in your code, only to accidentally mess everything up and not remember what you did to break it?

With version control, you can not only have a back up, but have a detailed history of all the important milestones of your project. You can also share your work with others, and have multiple coders work on the same project at the same time.

How much does it cost?

Git itself is free! There are various hosting services out there that have different pricing models. For this lesson, we’ll be using GitHub.

What is GitHub?

GitHub is a hosting service for Git repositories. Don’t be confused by the similar name, Git and GitHub are completely different things. You can use Git with a variety of software packages and services. GitHub is just one of the most popular sites for open source projects.

GitHub (the website) is free for an unlimited number of users, and an unlimited number of open sourced repositories. However, they charge a monthly fee for private (not viewable by the public) repositories.

What is open source?

Open source means everyone can see, and download the code for your projects. This allows others to check out, learn from or even contribute to your work. There are a lot of open source software projects that are created and maintained by various members of the community, including Git itself!

Where else can I host git repos?

There are a lot of different git hosts out there. I would recommend checking out the following:

Visual Studio Online

Website: http://www.visualstudio.com/products/visual-studio-online-user-plans-vs
Cost: Unlimited projects and private repositories for up to 5 users. Charge for additional users.

BitBucket

Website: https://bitbucket.org/
Cost: Unlimited projects and private repositories for up to 5 users.

Do I have to use the GitHub client to use GitHub!

No you do not!

You can use any Git client to connect to GitHub. Many people control Git through text base commands, but I think it’s a lot easier to use a GUI tool.

There are other, more advanced clients you can use like Git Extensions or SourceTree. GitHub’s client very simple and bare bones, which I think is nice when you’re first learning, and why I chose it for this tutorial.

Setting up the GitHub Client:

Download GitHub Client

You can download the GitHub for Windows client by going to http://windows.github.com/

Create Account

To create an account for GitHub, go to https://github.com/join

Once you get your account set up, you can start the GitHub client on your computer and log in.

Configure settings

You will be given the option to set the name and email address you would like to have tied to your commits. Use an email address you don’t mind others seeing, as this information will be public!

If you are worried about spam, or simply don’t want your email address to be publicly listed, GitHub provides a private email address. Simply set your email address to “username@users.noreply.github.com” where username is your GitHub username.

For more information, follow the instructions here: https://help.github.com/articles/keeping-your-email-address-private

To be continued

On Wednesday, look for Part 1: Your first repository!

-Tobiah

Alpha Game Jam September 12th through 14th

Alpha Game JamTime for a new Game Jam! The Indie Game Developers of Silicon Valley meetup.com group will host “Alpha Game Jam” at Microsoft’s SF Campus on September 12th-14th.

Instead of just the normal monthly meetup, we wanted to run an event that encourages developers of all skill levels to get together, learn from each other, try something they have never done before… or just simply have fun making a new prototype.

There will be no strict rules on what kind or game you should make, or how you should make it. Bring an idea, or create one on the spot. Meet new teammates, or have your team all ready to go. All experience levels welcome, from newbies to veteran devs.

To sign up, go to the Indie Game Developers of Silicon Valley meetup.com page and RSVP. We will be using ChallengePost for the hackathon, and you can preregister there by going here.

One thing to note, this will NOT be an overnight event. We jamming until midnight each night, returning at 10am the next morning.

Spread the word, and I hope to see you there in San Francisco on September 12th!

-Tobiah

Art as a developer

Time for another “Ask Tobiah“:

How did you create the graphics and character designs for your first game? I know you are a developer. Did you do it by yourself? or find anyone for it? As a developer, it is a big challenge. I plan to use Unity.
-Tae Hwan Kim

Hey, just because I’m a “developer” doesn’t mean I am terrible at creating art!

I just happen, by pure coincidence, to be both a developer and terrible at art.

Continue reading

Monetization strategies for Windows markets

After the last two “Ask Tobiah” questions were about multiplatform development, time to change things up a bit:

How are monetization strategies different for the Windows markets? Any tips or tricks for success?
-Matthew Fossati

As an Evangelist from Microsoft, I don’t have access to numbers or percentages. Even if I did, I would not be able to share them due to privacy agreements unless given explicit permission to do so. But, I can speak from my own personal experience. Continue reading