April 30, 2017

Quick GitHub Tutorial

There are tons of great GitHub tutorials out there:


Which are super great, the thing is though, it can be somewhat intimidating and it can get confusing and sometimes you just want to make something do something quick and work from there instead of learning all the things and only then doing something.

So, for the purposes of reminding myself how to do these things as well as helping those who comment that they'd like to get to learning some GitHub but don't know where to start- hopefully this helps!

1. I have a file/folder/project I want to track- what do I do?!!

Calm down. Download git and install. It's not gonna do anything, so don't fret if you don't see a pop-up.

Open your Command Line Interpreter (terminal if osx, powershell if win) and navigate to the folder you want to track with git, here are some tools (type these in the command line to do things):

ls => lists all folders/files your terminal is currently at
cd => changes directory of where your terminal is currently pointed at
cd ~ => goes back (mind the blank space)

*click here for a crash course with the command line

Are you at the folder where your file is? Here's what mine looks like; I'm trying to track this brief list of water pokemon on my desktop: waterPokemon.rtf

Cool, now to begin tracking that file, you first need to initialize git!
Type: git init

Now, we need to add the list of water pokemon to the "Staging Environement". It's just something you need to do. If you try make git register (commit) without first adding, it's just not gonna do it, it needs to track it first!:
Type: git add <fileName>

After typing that, the CLI isn't going to do anything, so get the status on the current directory to see what's up:
Type: git status

You'll notice the file is ready to be committed, so commit it:
Type: git commit -m "super descriptive commit message!" <fileName>

Here's what you should see:

That's it! Now you're playing with power! :)

2. I want it to be on GitHub.com tho!

So you don't just want to track this thing locally? Then make a GitHub account.

On the front page of GitHub.com you should a green "New repository" button, click it:

If not, just go here

Fill out the details on the form and click the green "Create repository" button

After that GitHub.com will give you some options and since we already have a local repo that we just want to "push" into GitHub, copy and paste that option into your CLI:

Check your GitHub.com, your file should now be listed in the new project you created

That's it! Your folder/files whatever it was you were working on, are now on GitHub!

3. Interesting, but I thought GitHub/Git was about version control, not just putting your stuff online!

True true, so then...make a new branch!

Type: git branch <branchname>

It won't look like git did anything but,
Type: git branch <branchname>

This shows you a list the branches on the file you're tracking. The asterisk tells you the current branch you're on (master branch in my case). To switch to that new branch we made:
Type: git checkout <branchname>

Type: git branch

You'll see we're now in your new branch where you can make local edits to that file then push your edits to the remote version on GitHub by making a "Pull Request".

4. What's this whole pull request deal?!!

Well, it's how you push your local repository of a project to the "master" project. So say your friend was working on a file, you downloaded it, made changes to the file, "staged" it, "committed" it, and after you did all that locally, you finally decided to push it to the remote repository where the master is- so push your branch!

I've already saved my changes on the txt file, and staged & committed locally, now I'm just pushing remotely to make the pull request:
Type: git push origin <branchname>

Go to your GitHub and you'll now see an option to create a new Pull Request on the project:

After you make the pull request, the owner of project (you in this case) will be able to review it and merge it to their master copy if they want to:

That's pretty much all there is to it!

Well actually not, there's tons more to this. Many commands and methods approaches to version control on git (which is what makes it super powerful) but, there are way better tutorials out there to get you acquainted with those.

Thanks for reading!

No comments:

Post a Comment