-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathg04_git_ssh_main2master.txt
More file actions
96 lines (66 loc) · 2.63 KB
/
g04_git_ssh_main2master.txt
File metadata and controls
96 lines (66 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# --------------------------------------------------------------
The default branch name for new GitHub repositories
is not "master", it is now "main":
https://github.com/github/renaming
I still want to use "master".
So when I create a new repo, I rename
in browser rename from main to master.
Then locally run these commands:
git branch -m main master
git fetch origin
git branch -u origin/master master
git remote set-head origin -a
# --------------------------------------------------------------
Note - in 2021 GitHub switched their authentication rules.
Now you should use SSH.
You can add SSH key to your account or to a specific repository
(may be to a repo which is not yours, but you have access).
# --------------------------------------------------------------
Here how to add to your account
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
ssh-keygen -t ed25519 -C "your_email@example.com"
/Users/you/.ssh/github_myname/id_ed25519_github
eval "$(ssh-agent -s)"
open ~/.ssh/config
Host *
AddKeysToAgent yes
Host github.com
User myuser
HostName github.com
IdentityFile ~/.ssh/github_myname/id_ed25519_github
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519_github
# -------------------------------------
# Then copy/paste public key into Github website:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
# -------------------------------------
# Then switch the remote locally:
cd your_local_repo_dir
git remote set-url origin git@github.com:YouUser/YouRepo.git
git remote -v
origin git@github.com:YouUser/YouRepo.git (fetch)
origin git@github.com:YouUser/YouRepo.git (push)
git branch
* master
# -------------------------------------
Note: to add a new key to a company's private repo,
follow instructions here:
https://cloud.redhat.com/blog/private-git-repositories-part-2a-repository-ssh-keys
Basically you need to generate the key pair
ssh-keygen -t ed25519 -C "first.last@gmail.com"
For example, you created these two keys:
$HOME/.ssh/github_myproject/github_id_ed25519
$HOME/.ssh/github_myproject/github_id_ed25519.pub
Then you update the .ssh/config file:
Host github.com
User githubuser
HostName github.com
IdentityFile /home/azureuser/.ssh/github_myproject/github_id_ed25519
IdentitiesOnly yes
Host *
AddKeysToAgent yes
Then login in github, go to the repo, click on settings (gear),
then on the left click on "Deploy keys",
and the on right-top click on "Add deploy key"
then follow instructions to paste the public key.
# -------------------------------------