I have a project with a few friends in GitLab, and there is of course the master branch, and there are some others too. When I cloned the repository, I created also an upstream with the command
git remote add upstream ...
git fetch upstream
git checkout upstream/test1
git branch -a
* (HEAD detached at upstream/test1)
remotes/origin/HEAD -> origin/master
git add .
git commit -m "Sample message"
git push -u origin test1
You don't appear to have a local branch named
test1. You have a remote branch named
test1 associated with your
You shouldn't be editing the
upstream/test1 branch directly. In fact, attempting to check that out should have yielded a warning:
$ git checkout upstream/test1 You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.
You should instead first check out a local branch that tracks the remote branch, which ought to look something like this:
$ git checkout test1 Branch test1 set up to track remote branch test1 from upstream by rebasing. Switched to a new branch 'test1'
After doing this, an undecorated
git push would push to the
upstream remote, while
git push origin test1 would push to your
origin remote. Adding the
-u flag there would switch the tracking branch so that instead of tracking
upstream/test1, your branch would track
origin/test1, so that future
git pull and
git push operations would refer to that remote branch (
origin/test1) by default.