Skip to content

Instantly share code, notes, and snippets.

@cbilgili
Created March 6, 2014 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbilgili/9392200 to your computer and use it in GitHub Desktop.
Save cbilgili/9392200 to your computer and use it in GitHub Desktop.
Git Initializing
Git Config
Check your Git configuration parameters:
$ git config -l --global
user.name=Daniel Kehoe
user.email=daniel@danielkehoe.com
The email address will identify you to any services that use your Git repo, such as GitHub and Heroku.
Life will be easier if you use the same email address for all services where you use Git (so sign up for GitHub and Heroku using the same address).
Ignore Files
When you use the rails new command, Rails creates a .gitignore file for you in your application root directory. You may want to modify it:
.bundle
db/*.sqlite3
log/*.log
tmp/
.DS_Store
The RailsApps project has a more extensive example .gitignore file you might want to examine.
Initialize Git For Your Rails Application
You’ll need to do this if you have created a new Rails application. If you’ve created a Rails application using the Rails Composer tool (“like the ‘rails new’ command on steroids”), the program will have done this for you already.
Be sure you are in your application’s root directory.
Initialize Git and check in your first commit:
$ git init
$ git add .
$ git commit -m 'initial commit'
The -m 'initial commit' argument attaches a comment (“m” for “message”) to the commit. You should include a comment with every commit.
You can check your commit status at any time with:
$ git status
Get a GitHub Account
Use a GitHub repository if you want an offsite copy of your work or you plan to share your work with others.
Get a free GitHub account if you don’t already have one. It’s advisable to register using the email address that you’ve used to configure git locally (see “Git Config” above).
Check that your GitHub account is set up properly:
$ ssh -T -p 443 git@ssh.github.com
If your account is set up correctly, you’ll see a message:
Hi ...! You've successfully authenticated, but GitHub does not provide shell access.
The first time you connect, you will be warned (by ssh) that you have not previously connected with the host at ssh.github.com:
The authenticity of host '[ssh.github.com]:443 ...' can't be established.
Are you sure you want to continue connecting (yes/no)?
Unless you are the victim of a particularly insidious and unlikely exploit, you can safely answer “yes.”
If you see an error message such as Host key verification failed, review GitHub’s document setting up Git and SSH keys or the guide troubleshoot common SSH Problems.
Save it to GitHub
Go to GitHub and create a new empty repository (https://github.com/repositories/new) into which you can push your local git repo.
Add GitHub as a remote repository for your project and push your local project to the remote repository:
$ git remote add origin git@github.com:YOUR_GITHUB_ACCOUNT/YOUR_PROJECT_NAME.git
$ git push origin master
At each stage of completion, you should check your code into your local repository:
$ git commit -am "some helpful comment"
Note the -am argument. Use -m to add a commit message. Use -a to automatically remove any files you may have marked for deletion (otherwise you have to use “git rm,” adding an additional step). You can combine -m and -a as -am.
Then push your changes to the remote repository:
$ git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment