Skip to content

Latest commit

 

History

History
161 lines (107 loc) · 4.83 KB

GIT-CHEATSHEET.md

File metadata and controls

161 lines (107 loc) · 4.83 KB

Git Cheatsheet

If you want to learn more about Git, read the Pro Git book (online & free).

Best practices

One-time configuration

Configure your identity

You must configure identity using your user name and e-mail address. This is important because every Git commit uses this information, and it's immutably baked into every commit you make. You should obviously replace your "John Doe" and [email protected] with your own information.

$> git config --global user.name "John Doe"
$> git config --global user.email [email protected]

Automagically exclude annoying .DS_Store files from your commits. (Mac only)

You can create a global ignore file in your home directory to ignore them:

$> echo ".DS_Store" >> ~/.gitignore

Run the following command to configure Git to use this file. You only have to do it once on each machine:

$> git config --global core.excludesfile ~/.gitignore

Frequent operations

Create a new empty repository

$> cd /path/to/projects
$> mkdir my-new-project
$> cd my-new-project
$> git init

Put an existing project on GitHub

$> cd /path/to/projects/my-project
$> git init

If you don't want to commit some files, create a .gitignore file listing them each on one line, e.g.

*.log
node_modules

Commit the project's files:

$> git add --all
$> git commit -m "Initial commit"

Create your new repository on GitHub, copy the SSH clone URL (e.g. [email protected]:MyUser/my-project.git), and add it as a remote:

$> git remote add origin [email protected]:MyUser/my-project.git

Push your master branch and track it (with the -u option):

$> git push -u origin master

Push my latest changes to the GitHub repository

Commit and push your changes:

$> git add --all
$> git commit -m "My changes"
$> git push origin master

If GitHub rejects your push, you should pull the latest changes first.

Pull the latest changes from the GitHub repository

If you have uncommitted change (check with git status), stage and commit them:

$> git add --all
$> git commit -m "My changes"

Pull the changes:

$> git pull

If you've worked on the same files, there might be a merge. If there is a merge conflict, resolve it and complete the merge with git commit.