Skip to content

Instantly share code, notes, and snippets.

@canton7
Created June 29, 2011 13:35
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save canton7/1053846 to your computer and use it in GitHub Desktop.
Save canton7/1053846 to your computer and use it in GitHub Desktop.
git push, tracking, and push.default

git clone path/to/test/repo.git

push.default = matching (the default)

git config push.default matching

git branch -a
   * master
     origin/master
     origin/test

Pushing a tracking branch of the same name

git checkout -t origin/test
   Branch test set up to track remote branch test from origin.
   Switched to new branch 'test'

echo one > test
git add test && git commit -m "Test file 1"
git push
  *Pushes master and test to origin*

echo two > test && git commit -am "Test file 2"
git checkout master
git push
  *Pushes master and test to origin*

git branch -D test

Pushing a tracking branch of a different name

git checkout -b origin_test origin/test
   Branch origin_test set up to track remote branch test from origin.
   Switched to new branch 'origin_test'

echo two_point_one > test && git add test && git commit -m "Test file 2.1"
git push
  *Pushes master to origin*

echo two_point_two > test && git commit -am "Test file 2.2"
git push origin
  *Pushes master to origin*

echo two_point_three > test && git commit -am "Test file 2.3"
git checkout master
git push
   *Pushes master to origin*

git branch -D test

Pushing a non-tracking branch of the same name

git checkout --no-track -b test origin/test
   Switched to new branch 'test'

echo three > test && git add test && git commit -m "Test file 3"

git push
   fatal: No destination configured to push to.
git push origin
   *Pushes master and test to origin*

echo four > test && git commit -am "Test file 4"

git checkout master
git push
   *Pushes master and test to origin*

git branch -D test

Pushing a non-tracking branch of a different name

git checkout --no-track -b origin_test origin/test
   Switched to new branch 'origin_test'

echo five > test && git add test && git commit -m "Test file 5"

git push
   fatal: No destination configured to push to.
git push origin
   *Pushes master to origin*

echo six > test && git commit -am "Test file 6"

git checkout master
git push
   *Pushes master to origin*
git push origin
   *Pushes master to origin*

git branch -D origin_test

push.default = tracking

(I'm using 1.7.4 msysgit, use push.default upstream for 1.7.6+)

git config push.default tracking

Pushing a tracking branch

git checkout -t origin/test
   Branch test set up to track remote branch test from origin.
   Switched to new branch 'test'

echo seven > test && git add test && git commit -m "Test file 7"

git push
   *Pushes test to origin*

git branch -D test

Pushing a non-tracking branch of the same or different name

git checkout --no-track -b test origin/test
   Switched to new branch 'test'

echo eight > test && git add test && git commit -m "Test file 8"

git push
   fatal: No destination configured to push to
git push origin
   fatal: The current branch test is not tracking anything.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment