Tuesday, February 26, 2013

No-Frills Guide to GitHub


“Being too busy to worry about backup, is like being too busy driving a car
  to put on a seatbelt.”
  — T.E. Ronneberg

Looking for a no-frills tutorial on using Git to make repositories of your code
available on GitHub?

You came to the right place. GitHub is a great place that allows you to back up your code,
display your work, and allow for collaboration. Backing up code is the key to never
losing any work. Ready to get started?

Note: This guide assumes you have a GitHub account and already have Git setup.

Go to GitHub and make a new repo called Project1. Now you want to minimize that
window and open up the Git Bash command line tool.

To begin, create a folder where your project can be saved.
For example reasons, we will call it ‘Project1’ for now.

Using Git Bash, navigate to the directory where you want to save it to.

Ex: cd c:/Users/Michael/

From there we can make the folder for the project using Git

Ex: mkdir Project1

Now we navigate into that folder and initialize Git.

Ex: git init

This will create an empty repository in that folder.

The next step would be the actual start of coding your project. All files should be
placed under the folder we created: Project1. You can even save them anywhere
and just copy and paste them into the Project1 folder when you’re ready to contiune.

When you are ready to add files to your Git repo run this add command.

Ex: git add .

Note: Using the . after add will add every file found in the folder.

If you want you can add files one at time but specifying.

An example would be: git add main.cpp

Have all your changes made and ready to make your 1st commit? Run the Git
commit command to commit changes you’ve made.

Ex: git commit -m “initial commit”

Where “initial commit” is your comments for the commit.

This will commit your code. Ready to see your code live on your GitHub page?
The next step will make your code available under the repositories part of your page.

This is called pushing. To push your code you must run this command first from
the Git Bash command line.

Ex: git remote add origin git@github.com:username/Project1.git

Where username is your GitHub account name.

The next command will actually push the code into the repo.

Ex: git push origin master

Now go to your GitHub profile page and you should see the code come up under
Project1.

If a push doesn’t want to work, you can force a push through using the following
command. Please be certain that you want forced pushed changes to occur before
pushing though.

To force a push use this command:

Ex: git push origin master --force

Now that you’ve gotten some code on GitHub you can explore the other commands
and options available. I just wanted to give you a quick idea of how to get code up and
running to display personal projects that you’ve completed. If you are looking for further practice or learning more about Git, you can try this site that teaches you about Git in 15 minutes.



~Michael




No comments:

Post a Comment