Gitで「error: The requested URL returned error: 401 Unauthorized while accessing 」が出た時の対処

Error内容

$ git clone https://gitlab.com/foo/bar.git
Initialized empty Git repository in /foo.git/
error: The requested URL returned error: 401 Unauthorized while accessing https://gitlab.com/foo/bar.git/info/refs

fatal: HTTP request failed

対処

リポジトリのURLにユーザー名を追加する。 https://ユーザー名@gitlab.com/foo/bar.git

$ git clone https://UserName@gitlab.com/foo/bar.git
Initialized empty Git repository in /foo.git/
Password: