Skip to content

Instantly share code, notes, and snippets.

@mjuhl
Last active December 19, 2015 15:39
Show Gist options
  • Save mjuhl/5978424 to your computer and use it in GitHub Desktop.
Save mjuhl/5978424 to your computer and use it in GitHub Desktop.

Read this first, especially chapter 2: Getting Started - git basics

Setup git

First, download and install the latest version of git.

Then, set your name and email address. These will be attached to your commits. Use the following commands:

git config --global user.name "Your Name Here"
git config --global user.email "your_email@example.com"

Then set the default push behavior.

git config --global push.default simple

git-flow

Follow these instructions to install git-flow. (You may need to install Homebrew or MacPorts first).

This article provides a good introduction to git-flow.

SourceTree

SourceTree is a great git client, and it's free. You can download it from here or from the Mac App Store.

Starting a new project

Create or checkout a project

  1. If starting a new project, create it on Springloops first.

  2. Next, you'll clone the project on your local machine. This can be done in SourceTree or via the command line.

     git clone [remote repository url here]
    

    This will create a local copy of the repository in a new directory.

  3. Setup the project to use git-flow.

     cd [the directory created above]
     git flow init -d
    
  4. Commit to the develop branch until you have a major change or feature to add. Then, you may want to start a feature branch using

     git flow feature start 'feature-name'
    

Pulling remote changes

To pull and automatically merge changes, type this:

git pull origin

If you want to pull the changes and manually merge them:

git fetch origin

Using pull rather than fetch usually works fairly well.

Pushing changes

Once you've made some commits, you need to push them back to the origin server (which is on Springloops). To push changes to develop, click the Push button in SourceTree, or type:

git push [remote-name] [branch-name]

For example:

git push origin develop

If someone else has pushed changes to the origin server in the meantime, your push will be rejected. You must first pull down the remote changes, then try pushing again.

Ignoring files

To ignore certain files or folders in your local repository, you need to add them to your .gitignore file.

Branches

Here's a quick overview of branches.

Current Branch

To see what branch you're currently on, you can type:

git status

Switching branches

git checkout develop
git checkout master
git checkout feature/login
# etc

Create a feature branch

Using git-flow, it's ok to make small changes on the develop branch, but when you want to make major changes, it's best to start a new feature branch.

git flow feature start login

This will create a branch named feature/login in your local repository based on develop.

To share your feature branch, you'll need to push it back to the origin.

git push origin feature/login

When you're finished with the feature and ready to merge it back in to develop, type:

git flow feature finish login

This will merge feature/login back into develop and delete the feature branch. Then, push your changes.

git pull origin develop
git push origin develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment