Thursday, January 6, 2011

Push/Fetch source to/from other remote/branch

  1. Push to other remotes
    1. List all remotes
      $ cat .git/config
      [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = git@192.168.0.1:/home/git/debug_version.git
    2. Add a remote named "origin2"
      $ git remote add origin2 git@192.168.0.1:/home/git/release_version.git
      $ cat .git/config

      [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = git@192.168.0.1:/home/git/debug_version.git
      [remote "origin2"]
            fetch = +refs/heads/*:refs/remotes/origin2/*
            url = git@192.168.0.1:/home/git/release_version.git

      $ git branch -a
      * master
         remotes/origin/HEAD -> origin/master
         remotes/origin/master
    3. Push branch master to origin2
      $ git push origin2 master
      $ git branch -a

      * master
         remotes/origin/HEAD -> origin/master
         remotes/origin/master
         remotes/origin2/master
    4. If you want to remove remote "origin2"
      $ git remote rm origin2
  2. Push to other branches
    1. List all branches
      $ cat .git/config
      [remote "origin"]
            fetch = +refs/heads/*:refs/remotes/origin/*
            url = git@192.168.0.1:/home/git/debug_version.git
      [branch "master"]
            remote = origin
           merge = refs/heads/master
    2. Create a branch named "golden"
      $ git branch golden
    3. Switch to golden
      $ git checkout golden
      $ git branch -a

      * golden
         master
         remotes/origin/master
    4. Push golden to remote origin/golden
      $ git push origin golden
      $git branch -a

      * golden
         master
         remotes/origin/master
         remotes/origin/golden
  3. Fetch from other branches (not master)
    1. Ref: http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git
    2. Download the branch master
      $ git clone git@192.168.0.1:/home/git/debug_version.git
      $ git branch -a

      * master
         remotes/origin/HEAD -> origin/master
         remotes/origin/golden
         remotes/origin/master
    3. If you want to take a peek at golden on upstream
      $ git checkout origin/golden
    4. Fetch from branch golden
      $ git checkout -b golden origin/golden
      $ git branch -a

      * golden
         master
         remotes/origin/HEAD -> origin/master
         remotes/origin/golden
         remotes/origin/master
Wayne

No comments:

Post a Comment