The issue is that your Docker build does not have your Git credentials.
If it is a private repo, the simplest fix is to make a build argument with a personal access token:
ARG GIT_TOKEN
RUN git clone https://${GIT_TOKEN}@github.com/username/your-repo.git
Then build with:
docker build --build-arg GIT_TOKEN=your_token_here -t myimage .
Just make sure that you are using a personal access token from GitHub, and not your password - GitHub does not allow password auth anymore.
If it is a public repo and is still not working, try:
RUN git config --global url."https://".insteadOf git://
RUN git clone https://github.com/username/repo.git
Sometimes the git:// protocol will mess up Docker images.
Edit: Also, as mentioned in comments, be careful about tokens in build args - because they may appear in image history, and this could pose a risk. For production purposes, consider using Docker BuildKit's --mount=type=ssh option instead.