Git, though remarkably handy and powerful, is also remarkably hard to use sometimes. Though you can learn the basics easily enough, it can be really tough to dig yourself out of certain corners if you don’t understand what’s going on under the covers.
This page provides links to documents, how-tos, cheat sheets, tips, and tricks related to learning and using git.
This will checkout the v1-stable branch in the “origin” remote repository, and will put it in a new local branch called “v1-stable”. By default, git will cause this branch to “track” the remote branch (meaning “push” and “pull” will work as epxected, pushing to or pulling from that remote branch).
Removing a remote branch28 Apr 2008
Most places on the web will tell you this isn’t possible, but one blog gave this helpful little tip:
The authors.txt file mentioned above is the file attached, below. Note that for large repositories, the ‘fetch’ command here can take quite some time (Basecamp took almost an hour and a half).
Once the fetch finishes, we just need to do some cleanup. First, let’s kill all of the remote tracking branches that we no longer need.
git branch -r
git branch -r -d stale-branch stale-branch …
Where “stale-branch” is the name of a remote-tracking branch that we no longer need.
Next, we can run prune to get rid of any orphaned objects, and gc to clean things up:
Then, we can repack everything optimally:
git repack -f -a -d --depth=500 --window=500
Finally, we check out any remote tracking branches, so that when we later push to the final repository location, the branches get remembered:
git checkout -b branch-name branch-name
The branch-name is specified twice because the first one is the name you want to give the local branch, and the second is the name of the remote branch you want to track. Do the above for each branch (“branch-name”) that you want to keep.
Note that if the branch that was checked out upon completion of the fetch was not the master (trunk), then you’ll need to use “git branch -m” to rename the current branch to what was actually checked out, and then checkout trunk as master (git checkout -b master trunk).
Once that is done, we can create our new “bare” repository, where we will all push to and pull from:
sudo -u app mkdir -m 0770 exampleapp.git
sudo -u app git --bare init --shared=group
Then, we move back to our converted repository, and push it all to our bare repository:
git push --all /u/git/exampleapp.git
The “--all” flag tells git that we want to push all branches, not just the current branch. Once that is done, you should be able to clone the new repository from your local machine: