Git Sparse Checkout Exclude


Warning: count(): Parameter must be an array or an object that implements Countable in /home/cbc8fzob0jbt/domains/uhleeka.com/html/blog/wp-content/plugins/uhleeka-codebox/uhleeka-codebox.php on line 65

To exclude a directory, first include everything (e.g. /*), then exclude the specific folder or file:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git config core.sparsecheckout true

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo '/*' > .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo '!a_directory_i_want_to_exclude/' >> .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git read-tree -m -u HEAD

This works with git 2.1.4

$ git --version
git version 2.1.4
Filed Under: Git | Tagged:

Bash Setup

Base:

#green (local)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile
#cyan (remote)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[36m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile
#red (root)
echo "export PS1='\[\e]0;\w\a\]\n\[\e[31m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "export HISTSIZE=50000" >> ~/.bash_profile
echo "export HISTFILESIZE=50000" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "alias ls='ls -al --color=auto'" >> ~/.bash_profile
echo "alias grep='grep --color=auto'" >> ~/.bash_profile
echo "alias sudo='sudo '" >> ~/.bash_profile
echo "alias vi='vim'" >> ~/.bash_profile

source ~/.bash_profile

curl -o ~/.vimrc http://amix.dk/vim/vimrc.txt

Git:

echo "" >> ~/.bash_profile

echo "function ps1_git_branch {" >> ~/.bash_profile
echo "    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/';" >> ~/.bash_profile
echo "}" >> ~/.bash_profile
echo "export PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\$(ps1_git_branch)\[\e[0m\]\n\$ '" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "export HISTSIZE=50000" >> ~/.bash_profile
echo "export HISTFILESIZE=50000" >> ~/.bash_profile

echo "" >> ~/.bash_profile

echo "alias ls='ls -al --color=auto'" >> ~/.bash_profile
echo "alias grep='grep --color=auto'" >> ~/.bash_profile
echo "alias sudo='sudo '" >> ~/.bash_profile
echo "alias vi='vim'" >> ~/.bash_profile
echo "alias gitlog='git log --graph --pretty=format:'\''%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit --date=relative'" >> ~/.bash_profile

git config --global push.default simple
git config --global color.ui auto

source ~/.bash_profile

curl -o ~/.vimrc http://amix.dk/vim/vimrc.txt

Add git branch to a bash prompt

Add the following code to ~/.bash_profile or ~/.bashrc.

function ps1_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/'
}

export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\$(ps1_git_branch)\[\e[0m\]\n\$ "

When in a folder that contains a .git repository, the current branch will show up in parenthesis.

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$

Looking for something more complicated? Check out richardhansen’s https://github.com/git/…/git-prompt.sh contribution.

Git Sparse Checkout

From the root of your local git repo:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git config core.sparsecheckout true

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo a_directory_i_want_to_include/ > .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ echo another_directory_i_want_to_include/ >> .git/info/sparse-checkout

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ git read-tree -m -u HEAD

Validate:

uhleeka@uhleeka.local /cygdrive/c/projects/test (master)
$ ls
a_directory_i_want_to_include/ another_directory_i_want_to_include/
Filed Under: Git | Tagged: