blob: dd4edad6af9e0f1e66b2db581caac2a7d2667796 (
plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
GIT REPOSITORY SETUP SUMMARY
===========================
OVERVIEW
--------
You have a local bare repository (demo.git) as the source of truth, mirrored on a VPS.
Users can clone from the VPS and push/pull changes to stay synchronized.
Branch: main (not master)
INITIAL VPS SETUP (done once)
-----------------------------
SSH into VPS as ubuntu user:
ssh ubuntu@your_vps_ip
Create bare repository as git user:
sudo su - git
mkdir -p /home/git
cd /home/git
git init --bare demo.git
The bare repository is ready to receive pushes.
YOUR LAPTOP CONFIGURATION
-------------------------
Working directory: /home/me/demo
Bare repository: /home/me/demo.git
Set up dual remotes to push to both local and VPS:
cd /home/me/demo
git remote set-url origin /home/me/demo.git
git remote add vps ssh://git@your_vps_ip/~/demo.git
git remote set-url --add --push origin /home/me/demo.git
git remote set-url --add --push origin ssh://git@your_vps_ip/~/demo.git
First sync (push all branches and tags):
git push -u origin --all
git push -u origin --tags
Verify configuration:
git remote -v
When you push, both repositories are updated:
git push origin main
USER ACCESS SETUP (per user)
----------------------------
One-time setup for each user:
1. User generates SSH key (if they don't have one):
ssh-keygen -t ed25519 -C "their_email@example.com"
(accept defaults)
2. User sends you their public key (~/.ssh/id_ed25519.pub)
3. You add their key to the git user on VPS:
ssh ubuntu@your_vps_ip
sudo su - git
cat >> ~/.ssh/authorized_keys
(paste their public key, then Ctrl+D)
CLONING FROM VPS
----------------
Users clone with:
git clone ssh://git@your_vps_ip/~/demo.git
This automatically sets up 'origin' remote pointing to the VPS repository.
Verify:
git remote -v
PUSHING CHANGES
---------------
Users push to VPS with:
git push origin main
This updates the VPS repository, which you can then pull from your laptop.
PULLING CHANGES
---------------
If user1 pushed to VPS and user2 wants to get their changes:
User2 pulls from VPS:
git pull vps main
If user2 also has a local bare repo, they can then sync it:
git push origin main
YOUR LAPTOP - PULLING USER CHANGES
----------------------------------
When users push to the VPS, pull those changes to your laptop:
git pull vps main
Then push to your local bare repo:
git push origin main
PATHS EXPLAINED
---------------
/home/me/demo.git - Your local bare repository (source of truth)
/home/me/demo - Your local working directory
ssh://git@your_vps_ip/~/demo.git - Remote VPS repository
The ~/demo.git path expands to /home/git/demo.git but hides the full path.
SUMMARY OF WORKFLOWS
--------------------
YOUR LAPTOP:
git push origin main (pushes to both local demo.git and VPS)
git pull vps main (pulls changes pushed by other users to VPS)
USER CLONING:
git clone ssh://git@your_vps_ip/~/demo.git
USER PUSHING:
git push origin main (pushes to VPS)
USER PULLING:
git pull origin main (pulls from VPS)
OR
git pull vps main (if they have dual origins like you do)
KEY POINTS
----------
- Main branch is 'main' (default since Git 2.28)
- SSH key authentication: secure and requires minimal setup
- VPS path is hidden using ~/ syntax
- Users need SSH keys added to ~/.ssh/authorized_keys on VPS
- All pushes and pulls use SSH (ssh://git@your_vps_ip/~/demo.git)
|