Basic Git Setup and Use

Updated . Posted . Visible to the public.

Set Up Git

Note: This is a condensed version. For the full treatment, look here Show archive.org snapshot .

Now that you have Git installed, it's time to configure your settings. To do this you need to open the command line.

Username

First you need to tell git your name, so that it can properly label the commits you make.

git config --global user.name "Your Name Here"    
# Sets the default name for git to use when you commit  

Email

Git saves your email address into the commits you make. We use the email address to associate your commits with your GitHub account.

git config --global user.email your_email@youremail.com  
# Sets the default email for git to use when you commit  

Your email address for Git should be the same one associated with your GitHub account. If it is not, see this guide Show archive.org snapshot for help adding additional emails to your GitHub account. If you want to keep your email address hidden, this guide Show archive.org snapshot may be useful to you.

Global Excludes File

Set your excludes at the global level and you won't have to redo them for every repo you create. First create a file named .gitignore_global and store it in your home directory (C:\Users<your_user_name>). Then execute the following command:

git config --global core.excludesfile "C:\Users\<your_user_name>\.gitignore_global"

Editor

You can set the editor Git will use for commit messages.

git config --global core.editor "subl -w"

Command Aliases

Tired of typing all those long command names? Use aliases instead!

git config --global alias.co checkout

Overriding settings in individual repos

The steps listed above show you how to set your user info globally. This means that no matter which repo you work in on your computer, you'll be making commits as that user. If you find yourself needing to make commits with different user info for a specific repo (perhaps for work vs personal projects), you will have to change the info in that repo itself.

cd my_other_repo
# Changes the working directory to the repo you need to switch info for

git config user.name "Different Name"
# Sets the user's name for this specific repo

git config user.email differentemail@email.com
# Sets the user's email for this specific repo

Now your commits will be "blamed" on (associated with) the new user name and email whenever working in the specified repo.

Sample Global .gitconfig File

[user]
    name = Joseph Arsenault
    email = jarsen@earthlink.net
[core]
    excludesfile = C:\\Users\\Joseph\\.gitignore_global
    editor = subl -w
[alias]
    co = checkout

Sample Global .gitignore File

# See http://help.github.com/ignore-files/ for more about ignoring files.

# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
#   git config --global core.excludesfile ~/.gitignore_global

# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

# Ignore other unneeded files.
doc/
*.swp
*~
.project
.DS_Store 

Use Git

Create a new repository on the command line

git init
git add .
git commit -m "first commit"
git remote add origin https://github.com/jarsenx/first_app_windows.git
git push -u origin master

Push an existing repository from the command line

git remote add origin https://github.com/jarsenx/first_app_windows.git
git push -u origin master

Changing a remote url

git remote set-url origin http://<<hostname>>:<<port>>/git/<<repo_name>>.git
Profile picture of jarsen
jarsen
Last edit
Posted by jarsen to Ruby on Rails (2013-03-14 16:59)