Ubuntu环境下本地共享Git仓库的拉取推送与协作权限问询
Hey there! Let's walk through how your colleague can set up your access to that shared internal Git repo, plus the workflow for reviewing and merging your changes—no GitHub required. I’ve handled this exact setup for internal team projects plenty of times, so here’s the breakdown:
Since this is an internal shared server, the simplest approach is file system-level permissions, but we can cover a more robust option too.
Option 1: Basic File System Permissions (Quick & Easy for Small Teams)
Your colleague needs to make sure you have read/write access to the repo's directory on the server:
- First, create a shared user group for your team (if it doesn't exist already):
sudo groupadd dev-team - Add both your server username and theirs to this group:
sudo usermod -aG dev-team your-ubuntu-username sudo usermod -aG dev-team colleague-username - Update the repo directory's ownership and permissions to let the group access it:
# Replace /path/to/shared/repo.git with the actual repo path sudo chown -R :dev-team /path/to/shared/repo.git sudo chmod -R g+rw /path/to/shared/repo.git # Ensure new files inherit the group permission sudo chmod g+s /path/to/shared/repo.git
With this setup, you’ll have full pull (and push, if needed) access to the repo.
Option 2: Fine-Grained Permissions (For Larger Teams)
If your team needs stricter controls (like read-only access for some members, or branch-specific restrictions), your colleague can set up Gitolite. It’s a lightweight tool that manages Git permissions via a config file. They’ll need to:
- Install Gitolite on the server
- Add your SSH public key to their admin repo
- Define rules in the
gitolite.conffile (e.g., allow you to pull all branches but only push to feature branches)
This is more work upfront but scales better for bigger teams.
Without GitHub, you’ll use Git’s native workflows to collaborate. Here are two common, practical approaches:
Workflow 1: Feature Branch Collaboration (Most Common)
This keeps your work isolated until it’s reviewed:
- You create a feature branch locally for your work:
git checkout -b feature/your-feature-description # Do your work, commit changes git add . git commit -m "Add user profile edit functionality" - Push your feature branch to the shared server:
git push origin feature/your-feature-description - Notify your colleague to review. They’ll pull your branch locally to check:
git fetch origin git checkout feature/your-feature-description # Run tests, review code, check for bugs - If approved, your colleague merges it into master:
git checkout master # Use --no-ff to preserve branch history for easier debugging git merge --no-ff feature/your-feature-description # Push the updated master to the server git push origin master - Clean up the feature branch (local and remote):
# Delete local branch git branch -d feature/your-feature-description # Delete remote branch git push origin --delete feature/your-feature-description
Pro tip: Always pull the latest master into your feature branch before pushing to avoid merge conflicts:
git checkout feature/your-feature-description git pull origin master # Resolve any conflicts, commit, then push
Workflow 2: Patch-Based Review (For Formal/Remote Teams)
If you prefer using email or internal chat to share changes, you can generate patches:
- Create a patch file for your recent commits (replace
3with the number of commits you want to share):
This createsgit format-patch -3 origin/master.patchfiles you can send to your colleague. - Your colleague applies the patch to their local repo to review:
# To just preview changes git apply --stat 0001-Add-user-profile-edit.patch # To apply the patch to their working directory git apply 0001-Add-user-profile-edit.patch # Or to merge it directly into a branch git am 0001-Add-user-profile-edit.patch - Once approved, they merge the changes into master and push to the server.
内容的提问来源于stack exchange,提问作者Majid Azimi

