How to setup a remote GIT repository and play with branching

Given, you are a new GIT user/admin and want to setup an SVN like client-server architecture for your git repositories, wherein a server hosts the repository and many developers use that repository to track source code.

Do checkout Peepcode’s screencast on using Git. It is a MUST watch for any new Git user/admin.

(we cannot create a –bare repo as redmine needs a .git directory, while –bare does not creates a .git dir)
git init
git add .
git commit -m “initial import”

git clone
git remote show origin # Confirm that master is tracking master
git commit -a -m “some changes”
git push # push to origin, content from local master as master is tracking master

## Creating a new branch on the clone
git branch experiment
git commit -av “changes i made”
git push origin experiment # To be done only once after creating a branch. Next time onwards, just “git pull/push”.
git remote show origin # confirm that master is tracking master, experiment on local is tracking experiment on origin

## Using someone’s branch from origin
git branch -a
-> *master
-> origin/master
-> origin/new_experiment
git branch –track new_experiment origin/new_experiment # Creates a new tracker with new_experiment of local is tracking new_experiment on origin
git branch -a
-> *master
-> new_experiment
-> origin/master
-> origin/new_experiment
git checkout -b new_experiment
git commit -av “my changes to new_experiment”
git push # Commits changes to new_experiment branch

Once you are through with creating initial repos, and your branches on local are tracking the respective branches on remote, pushing/pulling is just a matter of doing “git push” and “git pull”.

I am simply loving it… err… git :)

Leave a Reply