GitCredentials » History » Version 4
Tech-X Corporation, 06/28/2019 11:31 AM
1 | 1 | Tech-X Corporation | # Git Credentials |
---|---|---|---|
2 | |||
3 | Private git repos require a username and password to clone and to push. |
||
4 | |||
5 | In the near future, bilder may require access to private git repos. |
||
6 | |||
7 | 2 | Tech-X Corporation | This document details how to cache your git credential so that you do not have to enter them interactively, and so that bilder will not fail to clone required git repositores. |
8 | |||
9 | You should store your git credentials as soon as possible on all machines where you expect to run bilder. |
||
10 | 1 | Tech-X Corporation | |
11 | 3 | Tech-X Corporation | ## Login directory |
12 | 1 | Tech-X Corporation | |
13 | 3 | Tech-X Corporation | ~ refers to the login, or home, directory. In some cases, git does not expand ~, and therefore will request interactive entry of credentials. For this reason, these instructions use the explicit home directory instead of ~. Git documentation does refer to ~, but this does not work for accessing github.com credentials. |
14 | 1 | Tech-X Corporation | |
15 | 3 | Tech-X Corporation | ## Windows |
16 | 1 | Tech-X Corporation | |
17 | 3 | Tech-X Corporation | Open a Cygwin terminal. To find your login directory, enter |
18 | |||
19 | |||
20 | > pwd |
||
21 | |||
22 | |||
23 | Your login directory should be /winsame/{username}. |
||
24 | |||
25 | Create the file /winsame/{username}/.git-credentials containing line(s) of the form: |
||
26 | |||
27 | > https://username:password@server.com |
||
28 | |||
29 | |||
30 | For ice.txcorp.com, where Tech-X git repos will be stored, the line will be: |
||
31 | |||
32 | > https://username:password@ice.txcorp.com |
||
33 | |||
34 | If you have a github.com account, you may cache your github.com credentials in the same file: |
||
35 | |||
36 | > https://username:password@ice.txcorp.com |
||
37 | > https://github_username:github_password@github.com |
||
38 | |||
39 | Because this is a plain text file containing your password(s), change permissions of the file so only you can read it: |
||
40 | |||
41 | > chmod 600 ~/.git-credentials |
||
42 | |||
43 | ### Configure git to use .git-credentials |
||
44 | |||
45 | git may be configured to check .git-credentials for all repos (--global), or for a single git repo. |
||
46 | |||
47 | To configure for global access, use the command: |
||
48 | |||
49 | > git config --global credential.helper 'store --file=/winsame/{username}/.git-credentials' |
||
50 | |||
51 | This command adds lines to /winsame/{username}/.gitconfig: |
||
52 | |||
53 | > [credential] |
||
54 | > helper = store --file=/winsame/{username}/.git-credentials |
||
55 | |||
56 | To configure git to check .git-credentials for a specific clone or master |
||
57 | |||
58 | cd to the clone and execute |
||
59 | |||
60 | > git config credential.helper 'store --file=/winsame/{username}/.git-credentials' |
||
61 | |||
62 | This command modifies the file /winsame/{username}/.git-credentials: |
||
63 | |||
64 | > {clone}/.git/config |
||
65 | |||
66 | |||
67 | ## Linux |
||
68 | |||
69 | Open a terminal. To find your login directory, enter |
||
70 | |||
71 | > pwd |
||
72 | |||
73 | Your login directory should be /home/research/{username}. If it is different, note the login directory and modify the instructions below to create .git-credentials |
||
74 | |||
75 | Create the file /home/research/{username}/.git-credentials containing line(s) of the form: |
||
76 | |||
77 | > https://username:password@server.com |
||
78 | |||
79 | 1 | Tech-X Corporation | For ice.txcorp.com, where Tech-X git repos will be stored: |
80 | |||
81 | 3 | Tech-X Corporation | > https://username:password@ice.txcorp.com |
82 | 1 | Tech-X Corporation | |
83 | If you have a github.com account, you may cache your github.com credentials in the same file: |
||
84 | |||
85 | 3 | Tech-X Corporation | > https://username:password@ice.txcorp.com |
86 | > https://github_username:github_password@github.com |
||
87 | 1 | Tech-X Corporation | |
88 | 3 | Tech-X Corporation | |
89 | 1 | Tech-X Corporation | Because this is a plain text file containing your password(s), change permissions of the file so only you can read it: |
90 | |||
91 | 3 | Tech-X Corporation | > chmod 600 ~/.git-credentials |
92 | 1 | Tech-X Corporation | |
93 | 3 | Tech-X Corporation | ### Configure git to use .git-credentials |
94 | 1 | Tech-X Corporation | |
95 | git may be configured to check ~/.git-credentials for all repos (--global), or for a single git repo. |
||
96 | |||
97 | 4 | Tech-X Corporation | To configure for global access, use the command: |
98 | |||
99 | 3 | Tech-X Corporation | > git config --global credential.helper 'store --file=/home/research/{username}/.git-credentials' |
100 | 1 | Tech-X Corporation | |
101 | 3 | Tech-X Corporation | This command adds lines to /home/research/{username}/.gitconfig: |
102 | 1 | Tech-X Corporation | |
103 | 3 | Tech-X Corporation | > [credential] |
104 | > helper = store --file=/home/research/{username}/.git-credentials |
||
105 | 1 | Tech-X Corporation | |
106 | |||
107 | 3 | Tech-X Corporation | To configure git to check .git-credentials for a specific clone or master |
108 | 1 | Tech-X Corporation | |
109 | cd to the clone and execute |
||
110 | |||
111 | 3 | Tech-X Corporation | > git config credential.helper 'store --file=/home/research/{username}/.git-credentials' |
112 | 1 | Tech-X Corporation | |
113 | 3 | Tech-X Corporation | |
114 | 1 | Tech-X Corporation | This command modifies the file: |
115 | |||
116 | 3 | Tech-X Corporation | > {clone}/.git/config |
117 | 1 | Tech-X Corporation | |
118 | |||
119 | 3 | Tech-X Corporation | ## Mac |
120 | |||
121 | Open a terminal. To find your login directory, enter |
||
122 | |||
123 | > pwd |
||
124 | |||
125 | Your login directory should be /home/research/{username}. If it is different, note the login directory and modify the instructions below to create .git-credentials |
||
126 | |||
127 | Create the file /home/research/{username}/.git-credentials containing line(s) of the form: |
||
128 | |||
129 | > https://username:password@server.com |
||
130 | |||
131 | For ice.txcorp.com, where Tech-X git repos will be stored: |
||
132 | |||
133 | > https://username:password@ice.txcorp.com |
||
134 | |||
135 | If you have a github.com account, you may cache your github.com credentials in the same file: |
||
136 | |||
137 | > https://username:password@ice.txcorp.com |
||
138 | > https://github_username:github_password@github.com |
||
139 | |||
140 | Because this is a plain text file containing your password(s), change permissions of the file so only you can read it: |
||
141 | |||
142 | > chmod 600 ~/.git-credentials |
||
143 | |||
144 | ### Configure git to use .git-credentials |
||
145 | |||
146 | git may be configured to check ~/.git-credentials for all repos (--global), or for a single git repo. |
||
147 | 4 | Tech-X Corporation | |
148 | To configure for global access, use the command: |
||
149 | 3 | Tech-X Corporation | |
150 | > git config --global credential.helper 'store --file=/home/research/{username}/.git-credentials' |
||
151 | |||
152 | This command adds lines to /home/research/{username}/.gitconfig: |
||
153 | |||
154 | > [credential] |
||
155 | > helper = store --file=/home/research/{username}/.git-credentials |
||
156 | |||
157 | To configure git to check .git-credentials for a specific clone or master |
||
158 | |||
159 | cd to the clone and execute |
||
160 | |||
161 | > git config credential.helper 'store --file=/winsame/{username}/.git-credentials' |
||
162 | |||
163 | This command modifies the file: |
||
164 | |||
165 | > {clone}/.git/config |
||
166 | |||
167 | |||
168 | ### Mac Keychain |
||
169 | |||
170 | 1 | Tech-X Corporation | The default credential.helper for Mac OS X is Keychain application. git refers to this as *osxkeychain*. |
171 | |||
172 | If you are using bilder on a Mac, git will check for credentials in *osxkeychain*. |
||
173 | |||
174 | If you have additionally configured git to check ~/.git-credentials, it will check for the server credentials in that file. |
||
175 | |||
176 | 3 | Tech-X Corporation | When git first uses the credentials in ~/.git-credentials, it will automatically create a Keychain internet password entry using the credentials in ~/.git-credentials. |
177 | 1 | Tech-X Corporation | |
178 | 3 | Tech-X Corporation | ### Checking for server credentials in Keychain |
179 | |||
180 | 1 | Tech-X Corporation | You may check on the command line for the existence of a stored credential in Keychain: |
181 | |||
182 | 3 | Tech-X Corporation | > security find-internet-password -s github.com |
183 | 1 | Tech-X Corporation | |
184 | The result of this command will be |
||
185 | * 0 - server credential found in keychain |
||
186 | * 44 - server credential not found in keychain |