DBS
DBS

Reputation: 1147

Move and rename files in github

I am using the Git Bash on Windows 10, not on the Linux command line.

I have files in a GitHub repo in a dir like such subdir1/abc-hello.md. There are also other files in the directory. I would like to move these files to another directory in the same repo and rename them by removing the "abc-" (subdir2/hello.md). I know how to do this one by one using git mv, but I would like to do this in a bulk move while maintaining the file history. I've read some other threads, but I'm new to bash scripting and can't get this to work.

Upvotes: 2

Views: 125

Answers (1)

phd
phd

Reputation: 94453

cd subdir1
for file in abc-*.md; do
    newname=${file##abc-} # Remove "abc-"
    git mv $file ../subdir2/$newname
done

I.e. loop over files (adapt the list of files or the wildcard pattern), change every filename by removing 'abc-', move.

Upvotes: 1

Related Questions