If you have no pre-existing history and just want to restart in the right place without moving too many files around, the duplicate question mentioned in the comments has the right answer for you.
If you want to keep existing history, but pretending it all happened a directory higher, here's a way to do it:
cd /project/src
git filter-branch --tree-filter 'mkdir src; git mv -k * .gitignore src'
cd ..
mv src junk
mv junk/src src
mv junk/.git .git
The filter-branch
command rewrites your history line so that all action happens beneath the src/
hierarchy. The rest moves things back in place. If there are non-tracked files lying around, they'll be left in the junk/
namespace in the end.
Warning: I used git mv -k .gitignore src
as a filter because it's the quick and easy way, but it will fail to move any dot-files you might have. (In which case, add them to the command.) The Right way would be to use git ls-files
as an index list, but it's remarkably tricky to get right as far as the move goes, so if you can avoid it, by all means do.