Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Monday, March 11, 2013

Managing git remote branches

When working with remote repositories with many branches, sometimes git bash responds a bit sluggishly. 

Fortunately there are few steps which can help to overcome problems with huge branches.

Clone with --single-branch

             git clone --single-branch [remote URL] [local folder]

With this git will not try to get references of all remote branches. As such getting all remote references is not an issue as git brings just references. However when checking for branches and inspecting remote, output gets cluttered with lot of references which are hardly of interest. More over with '--single-branch' remote spec is configured for default branch(master) only.  Further 'git remote update' will not try to check all references.
And to get to check all branches on remote repository 'git ls-remote [origin]' can be used. This just gets a view of all remote references rather than populating them.

However this comes with a slight discomfort. To be able to get a another branch, it is required to update refspec manually in config. Say to checkout remote branch b1, that branch should be added in config under remote.

            [remote "origin"]
            url = [remote url]
            fetch = +refs/heads/master:refs/remotes/origin/master
            fetch = +refs/heads/b1:refs/remotes/origin/b1

Then 'git remote udpate' updates b1. And it can be checkout as usual with 'git checkout b1'.

Similarly when remote branches are not of use but can not be removed from host repository they can be deleted locally

            git branch -r -d origin/b1

And pull, push and tracking for b1 goes normally.


Friday, September 30, 2011

gitignore skipping folder hierarchy

I was just trying to setup a new git repository for existing code base. Tree is something like this (names changed but structure retained)

├───apps
│   ├───bin
│   │   ├───x64
│   │   │   ├───Debug
│   │   │   └───Release
│   │   └───x86
│   │       ├───Debug
│   │       └───Release
│   └───libs
│       ├───Debug
│       └───Release
└───libs

.gitignore

Now my intention is to setup .gitignore file with following assumptions
1) libs at root and files below should be ignored
2) libs below apps and all files below should be considered for tracking
3) Debug and Release folders under apps\bin\x86|x64 should be ignored
4) Debug and Release folders under apps\libs should be considered for tracking

Help file of git ignore doesn't provide much help about placeholders and skip tokens. Though I wish a regex option could be ideal. After some hit and trial I could come up with following .gitignore file

/libs
*/bin/*/Debug
*/bin/*/Release

With this when I add and check for status I get desired result.


$git add .

$git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#       new file:   .gitignore
#       new file:   apps/apps1.txt
#       new file:   apps/libs/Debug/appslibsdebug.txt
#       new file:   apps/libs/Release/appslibsrelease.txt
#       new file:   apps/libs/appslibs1.txt
#