• August 11th, 2009

    My Very Own GIT Manual

    GIT confuses the hell out of me. I’m used to Subversion and Vault, and the translation isn’t always clear. Thankfully, there’s GitHub which makes it super easy to jump into using GIT.

    Unfortunately I constantly forget how to do simple tasks, not to speak of complex ones. This post is going to serve as my very own GIT manual so I can make these translations easily and not have to remember the intricacies.

    Updating your local repositories with remote changes: git pull

    To get the latest changes from your remote repository merged into your local master, run git pull. This is pretty much the same as running git fetch then git merge origin/master. Think of this as the GIT version of svn:update or Vault’s “Get Latest”.

    git pull
    

    Pushing local changes to your remote repository

    git add 'your file name'  #do this for each file or folder with changes
    git commit -a -m 'Your commit message'
    git push origin master
    

    Rejected!

    If a push to your remote repository gets rejected, it’s probably because remote files have been changed since you last used git pull. Run git pull then git push origin/master again. With any luck you should be in business.

    Push master to origin/master

    git push origin master
    > To git@github.com:<username>/<reponame>.git
    >  ! [rejected]        master -> master (non-fast forward)
    > error: failed to push some refs to 'git@github.com:<username>/<reponame>.git'
    

    Damn! Shit’s broke! Pull again then re-try your push!

    git pull
    > Merge made by recursive.
    
    git push origin master
    > Counting objects: 10, done.
    > Compressing objects: 100% (5/5), done.
    > Writing objects: 100% (6/6), 814 bytes, done.
    > Total 6 (delta 1), reused 0 (delta 0)
    > To git@github.com:<username>/<reponame>.git
    >    65a1527..79239e9  master -> master
    

    It worked!

    Updating your fork of another user’s repository

    get fetch origin
    git fetch upstream
    git merge upstream/master
    git push origin master
    

    There’s probably an easier way to do that, but I haven’t figured out as of this writing.

    Posted in Code/Projects, git | 2 Comments »

2 Comments »

  1. Avram Eisner  |  August 11, 2009   4:14 pm

    Good idea. One minor thing… I think that the -a option on ‘git commit’ automatically adds all updates so you don’t have to run ‘git add’ first.

  2. Avram Eisner  |  August 11, 2009   4:23 pm

    Let me know when you figure out the intricacies of manual merging – I think I’ll have to re-read that chapter in http://progit.org/book :P

Leave a comment





Un-Dumbify