I want to contribute to open source projects. I am working and living at 2 different locations. I have a VPN setup with a local central repository (in my home network) reachable from both locations. I have 2 developer desktop machines.
The difference to this similar question is that I want to use a server to which I clone the source code first and where I will create the branch and from where I merge the commits to the Gitlab remote repository.
Let us take the example of an open source project on Gitlab. I do a git clone https://gitlab.example.com/opensource.git
on my central server and then create a branch there git checkout -b new_feature
. Afterwards I clone it to both desktop machines via git clone central-server:/srv/data/Git/opensource
on both desktop machines. I developed and committed the changes locally on one of my developer machines. When I tried to push the changes I get an error message, see below. I tried the bare repository as well but got error messages as well. When I implemented the change and did the test, I want to push the changes from my central server to the Gitlab repository.
Question: what is the best workflow and the git commands here?
[user@laptop src]$ git branch
* new_feature
master
[user@laptop src]$ git status
On branch new_feature
Your branch is ahead of 'origin/new_feature' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
[user@laptop src]$ git push
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.90 KiB | 1.90 MiB/s, done.
Total 13 (delta 11), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/new_feature
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To central-server:/srv/data/Git/opensource
! [remote rejected] new_feature -> new_feature (branch is currently checked out)
error: failed to push some refs to 'central-server:/srv/data/Git/opensource'
[user@laptop src]$