Creating a Repo is Easy

CHEATSHEET:

CREATE A GIT REPOSITORY

If you're starting from an existing project in Git, you need to go to that project's directory in the terminal. Go ahead and navigate into that directory with 'cd /name of directory'. Then type the following:

$ git init

This creates a subdirectory named '.git' that contains all the needed files for a Git repo. So far you've installed Git, and now you have to begin tracking your project. Go ahead and type the following:

$ git add .
$ git commit -m 'your first commit is typed here, this is sample copy'

Now it's time to track changes to your project. As you edit your files, Git sees them as modified since your last commit. Go ahead and make a change to a file, or add a file in the project, and type this:

$ git status

At this point, you should see that Git has noticed a change in your directory. Untracked changes will remain that way until you commit them. When you 'git commit' them, you are staging changes, then tracking them. These two states are the key concepts that manage your style of development. A common life cycle that repeats itself often.

The best practice is to 'git commit' all changes with a clear description, annotating them for future observation. So when you or others revisit a change you've committed, you understand exactly what you've done.

If you haven't made any changes, you'll see the following:

$ git status
nothing to commit (working directory clean)

This means nothing has changed and there are no new files in your working directory. Now go ahead and add a change or file to your directory and type 'git status'.

$ git status
# On branch master # Changes not staged for commit: (use "git add ..." to updated what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: /name_of_file_changed.erb no changes added to commit (use "git add" and/or "git commit -a")

You should see the name of the file you've added. Go ahead and stage the file: git commit -m or git add . then add your description of the change in quotes: "I added a file to test git." Congratulations, you're now tracking files. For more info: go to Pro Gita great resource for all about Git.

When you create a project on Github, you will need to clone this repo to your local repository. See the next Cheatsheet: How to Clone a Git Repository for info on how do this, after you've gone through all the following steps.

Github is a place to put your project, you'll need a Github account to do this. Once you have an account set up, you'll then create a repository for each project.

Anyhow, first create a new repository in your Github account. It's the first graphic just right of your name in the top upper-right of your browser window.

Name your repository with a simple, easy to understand name. It will save you hours of guessing.

Describing your project is optional but when working with others it's quite useful.

Simply check a radio button to activate the settings. Making projects Public means everyone can see them, while making projects Private will require an invitation to others to see and join your project - useful when you're working with clients.

If you check the button "Initialize this repository with a README", this will allow you to clone the repo from the command line, or from the repository's front page immediately.


From the repo's front page, choose the "Clone in Mac" button and it will launch the Github App, where you'll be able to manage all repos through the Gitbhub GUI. If you don't have the Github app, you'll be prompted to download it.

Then click the button and you're all done.

You can start at the command line and create your local repository first.

Create your directory, install git and initialize your repo with a README file, where you describe your project, add documentation and provide contact information. All extremely useful from the get go.

Okay so here's what's happening: mkdir (make the directory)~(the tilde is your home directory) / Project-Folder, then cd / Project-Name, the git init stuff, and finally touch; the utility that creates the README file.

Now open the new README file from a text editor, and add a greeting "Yay Railsbridge!" Save it and close the file. Now commit your README file:

$ git add README
# Stages your README file, adding it to the list of files to be committed
$ git commit -m 'first commit'
# Commits your files, adding the message "first commit"

Now we have to push the commit, remember it's only local. Go to the next step.

Everything you've done so far has been local, which means nothing is on Github yet. Have your username handy, which is basicly the name of your account for this next step.

To connect your local repo to your GitHub account, you'll need to set up a remote for your repo and then push your commits to it:

$ git remote add origin: https://github.com/username/Name-of-App.git
# Creates a remote named "origin" pointing at your GitHub repository.
$ git push origin master
# Sends your commits in the "master" branch to Github

Go back to your repository on Github and you'll see your README file has been added. From this point forward, to push commits to your Gibhub repo, follow this recipe (only when working solo):

$ git status
# Do this at the beginning of each session to make sure you've committed all changes
$ git commit -m "the change description"
# If there is a change, then commit and stage it, if there's no change then keep working and when your ready git commit the new change
$ git push origin master
# Finally push any new commits to the remote repo