8

I'm adding multiple and large files into a repo.

git add .

It is taking a lot of time. Is there any way I can display the progress bar, so that I can know how much of the files is already added to the repo?

mrk
  • 8,059
  • 3
  • 56
  • 78

2 Answers2

16

No progress-bar, but, at least, you will get some feedback and see which files have already been added:

 git add --verbose .
sergej
  • 17,147
  • 6
  • 52
  • 89
  • not exactly what I wanted, but this helped - did upvote – mrk Jul 30 '18 at 09:19
  • Thanks @vanilla, I know. Maybe `pv` (pipe viewer) could help to get what you want. – sergej Jul 31 '18 at 06:40
  • does verbose also work with other commands such as commit, etc.? – mrk Jul 31 '18 at 06:48
  • 1
    @vanilla Yes, other commands support the verbose option too. But the actual behavior varies from command to command. commit, for example, adds the diff to the commit message. – sergej Jul 31 '18 at 07:35
5

Here is a one-liner, that calculates the progress percentage every second:

git add --verbose . > ../progress.txt & percent=0; while [[ $percent -le 99 && $percent -ge 0 ]]; do num1=$(cat ../progress.txt | wc -l); num2=$(find . -type f -not -path "./.git/*" | wc -l); percent=$((num1*100 / (num2 - 3) )); echo $percent"%"; sleep 1; done; echo "DONE"; sleep 1; rm ../progress.txt
  • While the progress less than 100%
  • Count the lines what git add generated ( num1 )
  • Count the all files in the folder except .git/* ( num2 )
  • Calculate percentage based on these numbers ( num1*100 / num2 )
    • We should subtract 3 from num2, because the find command echoes more lines than expected
  • the script generates a temporary progress.txt file, but it removes at the end

Example output:

12%
25%
50%
50%
75%
75%
100%
hlorand
  • 1,070
  • 10
  • 8
  • This one will create progress.txt in the repository you adding files into. Isn't that file will be added to the repo too? – Krypt Feb 25 '21 at 13:10
  • @Krypt the `git add` executes before the creation of `progress.txt` - but for maximum security I modified the path to `../progress.txt` so it creates this temporary file outside the git repo – hlorand Feb 28 '21 at 01:03
  • 1
    I used this command (in form before edit). It did, in fact, added progress.txt – Krypt Feb 28 '21 at 14:06