Skip to content

Instantly share code, notes, and snippets.

@Stephenitis
Created April 14, 2013 09:41
Show Gist options
  • Save Stephenitis/5382109 to your computer and use it in GitHub Desktop.
Save Stephenitis/5382109 to your computer and use it in GitHub Desktop.

GIT & GITHUB

Index

  1. New
  1. Branch
  2. Clone
  3. Fork
  4. Creating a github repo from a pre-existing local repo
  5. References

NEW


  1. Create a new Repo at https://github.com/repositories/new

  2. Create the README file

     mkdir ~/hello-world
     cd ~/hello-world
     git init
     touch README
    
  3. Commit your README

     git add README
     git commit -m 'first commit'
    
  4. Push your commit

create a remote named 'origin' pointing at your github repo

    git remote add origin [email protected]:<creator-name>/<project-name>.git

send your commits in the "master" branch to GitHub

    git push origin master 

(sometimes necessary, not sure when)

    git pull origin master

BRANCH


list branches

    git branch

Create a new branch

    git branch experiment

    git branch -b experiment (switches to it at the same time)

Switch to a branch

    git checkout experiment
    git checkout master

if you want to push the branch

    git push origin experiment

Merging

    git checkout master
    git merge experiment

Merge conflict resolution (manual)

  1. open up the file that failed

  2. Correct it where there are normal merge conflict markers

  3. run git add on the file to re-stage it, marking it as resolved

    git add lib/simplegit.rb

  4. commit the merge

    git commit

Deleting a branch

    git branch -d experiment # won't allow you to lose changes
    git branch -D experiment # will allow you to lose changes

CLONE


Go to the appropriate github repository and copy and past the command, e.g...

  git clone [email protected]:<creator-name>/<project-name>.git

FORK


  1. via github, fork project to your account (click "fork" button)

  2. normal clone from your own account

  3. Configure remotes

When a repo is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repo it was forked from. To keep track of the original repo, you need to add another remote named upstream:

Assign the original repo to a remote called "upstream"

    git remote add upstream <URL-OF-ORIGINAL-GIT>

Pull in changes not present in your local repository, without modifying your files

    git fetch upstream
  1. Push commits

     git push origin master
    
  2. Pull in upstream changes

     git fetch upstream
    
     git merge upstream/master
    

Creating a github repo from a pre-existing local repo

  1. create a github repo

  2. set your local git repo to view the url from step one as origin

     git remote add origin <URL_FROM_STEP_1>
    
  3. push

    git push origin master
    

REFERENCES


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment