Project

General

Profile

GitCredentials » History » Version 3

Tech-X Corporation, 06/28/2019 11:28 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 3 Tech-X Corporation
> git config --global credential.helper 'store --file=/home/research/{username}/.git-credentials'
98 1 Tech-X Corporation
99 3 Tech-X Corporation
This command adds lines to /home/research/{username}/.gitconfig:
100 1 Tech-X Corporation
101 3 Tech-X Corporation
> [credential]
102
>         helper = store --file=/home/research/{username}/.git-credentials
103 1 Tech-X Corporation
104
105 3 Tech-X Corporation
To configure git to check .git-credentials for a specific clone or master
106 1 Tech-X Corporation
107
cd to the clone and execute
108
109 3 Tech-X Corporation
> git config credential.helper 'store --file=/home/research/{username}/.git-credentials'
110 1 Tech-X Corporation
111 3 Tech-X Corporation
112 1 Tech-X Corporation
This command modifies the file:
113
114 3 Tech-X Corporation
> {clone}/.git/config
115 1 Tech-X Corporation
116
117 3 Tech-X Corporation
## Mac
118
119
Open a terminal.  To find your login directory, enter 
120
121
> pwd
122
123
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
124
125
Create the file /home/research/{username}/.git-credentials containing line(s) of the form:
126
127
> https://username:password@server.com
128
129
For ice.txcorp.com, where Tech-X git repos will be stored:
130
131
> https://username:password@ice.txcorp.com
132
133
If you have a github.com account, you may cache your github.com credentials in the same file:
134
135
> https://username:password@ice.txcorp.com
136
> https://github_username:github_password@github.com
137
138
Because this is a plain text file containing your password(s), change permissions of the file so only you can read it:
139
140
> chmod 600 ~/.git-credentials
141
142
### Configure git to use .git-credentials
143
144
git may be configured to check ~/.git-credentials for all repos (--global), or for a single git repo.
145
146
> git config --global credential.helper 'store --file=/home/research/{username}/.git-credentials'
147
148
This command adds lines to /home/research/{username}/.gitconfig:
149
150
> [credential]
151
>         helper = store --file=/home/research/{username}/.git-credentials
152
153
To configure git to check .git-credentials for a specific clone or master
154
155
cd to the clone and execute
156
157
> git config credential.helper 'store --file=/winsame/{username}/.git-credentials'
158
159
This command modifies the file:
160
161
> {clone}/.git/config
162
163
164
### Mac Keychain
165
166 1 Tech-X Corporation
The default credential.helper for Mac OS X is Keychain application.  git refers to this as *osxkeychain*.
167
168
If you are using bilder on a Mac, git will check for credentials in *osxkeychain*.
169
170
If you have additionally configured git to check ~/.git-credentials, it will check for the server credentials in that file.
171
172 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.
173 1 Tech-X Corporation
174 3 Tech-X Corporation
### Checking for server credentials in Keychain
175
176 1 Tech-X Corporation
You may check on the command line for the existence of a stored credential in Keychain:
177
178 3 Tech-X Corporation
> security find-internet-password -s github.com
179 1 Tech-X Corporation
180
The result of this command will be
181
 * 0 - server credential found in keychain
182
 * 44 - server credential not found in keychain