Studyon Minte9.com
Git




Git branch push



1) Master to master refused

	$ mkdir www && cd www
	$ echo 1 > index.htm
	$ git init
	$ git add . && git commit -m "m1"

	$ cd ..

	$ git clone /d/developments/testgit/www user1
	$ cd user1/
	$ less  index.htm
	1
	$ echo 2 > index.htm
	$ git commit -a -m "m2"

	$ git remote -v
	origin  d:/developments/testgit/www (fetch)
	origin  d:/developments/testgit/www (push)

	$ git push origin master
	remote: error: refusing to update checked out branch: refs/heads/master
	

2) Push to bare repository

	$ cd ..
	$ mkdir www.git && cd www.git
	$ git init --bare
	$ cd hooks/
	$ mv post-update.sample post-update
	$ vi post-update
	$ less post-update
	#!/bin/sh
	GIT_WORK_TREE=/d/developments/testgit/www git checkout -f

	$ cd ../user1/

	$ git remote -v
	origin  d:/developments/testgit/www (fetch)
	origin  d:/developments/testgit/www (push)

	$ git remote set-url origin /d/developments/testgit/www.git/

	$ git remote -v
	origin  d:/developments/testgit/www.git/ (fetch)
	origin  d:/developments/testgit/www.git/ (push)

	$ less index.htm
	2

	$ git push origin master
	$ cd ../www
	$ less index.htm
	2

3) New branch and push (doesn't change www/master)

	(hotfix)
	$ git checkout -b hotfix
	$ echo 4 > index.htm
	$ git commit -a -m "m4"
	$ git remote -v
	origin  d:/developments/testgit/www.git/ (fetch)
	origin  d:/developments/testgit/www.git/ (push)

	/user1 (hotfix)
	$ git push origin master
	Everything up-to-date

	/user1 (hotfix)
	$ git push origin hotfix
	Counting objects: 5, done.
	Writing objects: 100% (3/3), 242 bytes | 0 bytes/s, done.
	Total 3 (delta 0), reused 0 (delta 0)
	To d:/developments/testgit/www.git/
	 * [new branch]      hotfix -> hotfix

	/user1 (hotfix)
	$ cd ../www

	/www (master)
	$ less index.htm
	3
		// it should be 4 !!

        The reason for this is that git push by default pushes each branch to a branch with a matching name 
        on the remote, if such a branch exists there.

4) New branch also on www

	/www (master)
	$ git branch
	* master

	/www (master)
	$ git pull origin
	remote: Counting objects: 8, done.
	remote: Compressing objects: 100% (2/2), done.
	remote: Total 6 (delta 0), reused 0 (delta 0)
	Unpacking objects: 100% (6/6), done.
	From d:/developments/testgit/www
	 * [new branch]      hotfix     -> origin/hotfix
	   95542da..f54c483  master     -> origin/master
	You asked to pull from the remote 'origin', but did not specify
	a branch. Because this is not the default configured remote
	for your current branch, you must specify a branch on the command line.

	/www (master)
	$ git branch
	* master


	/www (master)
	$ git checkout -b hotfix
	Switched to a new branch 'hotfix'

	/www (hotfix)
	$ git pull origin hotfix
	From d:/developments/testgit/www
	 * branch            hotfix     -> FETCH_HEAD
	Auto-merging index.htm
	CONFLICT (content): Merge conflict in index.htm
	Automatic merge failed; fix conflicts and then commit the result.

	/www (hotfix|MERGING)
	$ less index.htm
	<<<<<<< HEAD
	3
	=======
	4
	>>>>>>> f29d8e78d60740c6379f731449cf1cfd610b7688


http://superuser.com/questions/80379/git-branches-how-exactly-do-they-work-can-i-remove-master-branch