Sourcetree existing repo has no brances and cannot create one - gitlab

I have an existing repo which I connected to my gitlab via ssh
I am just trying to create my branch in sourcetree so that i push my changes there but in getting an error "not a valid object name master"
is there any part that i skipped because my created repository cant create new branches? thanks for reading any help will be great.
TLDR: created and linked via gitlab repo in sourcetree with an existing one, cant create branch to push

Check first if you are creating your branch from an empty repository: there should be at least one commit.
If the repository is not empty, check if:
your remote GitLab repository expects a default branch 'main'
your local repository uses master as its main branch
If it is the case, rename your local branch
cd /path/to/local/repository
git branch -m master main
And make sure any future local repository starts with main:
git config --global init.defaultbranch main
Try again your branch creation in SourceTree.

Related

GitLab refuses to merge branch

Working with GitLab.
On GitLab the branch was created 11-feature1. Some commits were done to it. Then a new branch was created 22-feature2. The second branch was successfully merged into the main branch and work continue on the first 11-feature1. Now I cannot merge that branch into main.
I am doing on the local:
$ git fetch origin
$ git rebase origin/main
### few conflicts stemmed from 22-feature2 is found and solved
$ git push
It looks good on the local side. But the remote (GitLab) still refuses to merge the branch 11-feature1 into the main. The message, "The source branch is 8 commits behind the target branch".
What to do?
I am now morally ready to completely abandon the branch 11-feature1 on GitLab and recreate it anew from the current main (which already has 22-feature2 in it). How to do it?

remote: Pushed to branch other than [main, master], skipping build [duplicate]

I have a project hosted on Heroku and it's gotten to the point where I want to make an alternate test server (so I can test Heroku workers without messing up production).
I have already set up my main Heroku remote running my trunk and a Heroku-dev remote on which I wish to run an alternate branch.
My problem is that since my alternate branch isn't master, Heroku won't build it.
$ git push heroku-dev test
counting objects ...
...
Pushed to non-master branch, skipping build.
To git#heroku.com:example-dev.git
* [new branch] test -> test
Switching this build to master is not an option at the moment. Obviously one option is to create a whole new git repo that's a clone of my test branch, but that doesn't sound very ideal.
You can push an alternative branch to Heroku using Git.
git push heroku-dev test:master
This pushes your local test branch to the remote's master branch (on Heroku).
Comment from #Brian Armstrong:
Worth noting also, when you're ready to go back to master you need to do
git push -f heroku master:master
In my case, the default or base branch was develop, so i used:
git push heroku develop:master
In case git push heroku-dev test:master doesn't work for you, try git push heroku test:master.
Remember the "test" in "test:master" is the name of the new branch you are on.
You will need to pull the remote branch first before you can push the non master branch.
Run following command in you local repository
git pull https://heroku:YOUR_HEROKU_API_KEY#git.heroku.com/YOUR_APP_NAME.git

Push gitlab repository code to Google source repository

I followed below article to push gitlab repository code to Google cloud source repository but I'm getting an error on this command
git push -f google master
error: src refspec master does not match any.
error: failed to push some refs to 'https://source.developers.google.com/p/project/r/test/'
Article followed:
https://medium.com/#bamnet/cloud-source-repositories-gitlab-2fdcf1a8e50c
Is there anything , I'm doing wrong 😜? Any thoughts as to how I can avoid this error message?
src refspec master does not match any
The issue is the date of the article you are following: Aug. 2018.
GitLab Runner has changed since then, more precisely in May 2019.
The problem is described in this thread from May 2019:
Since we are using refspec to clone/fetch the repository, we checkout a specific commit and not checking out a specific branch.
When the script does git push master, the branch is nowhere to be found so git doesn’t know what to push.
That was because of, on GitLab side, MR 1203:
Basically, GitLab CE/EE sends refspecs parameter to GitLab Runner gitlab-org/gitlab-foss app/presenters/ci/build_runner_presenter.rb: this parameter is to used in GitLab Runners for fetching branch/tag refs from remote repository.
This change was introduced because we wanted GitLab Rails side to leverage respecs in order for issue 7380 "Combined ref pipelines (source+target branch)" though, there should not be a big difference between git clone $URL or mkdir $REPO_DIR && git remote add origin $URL && git fetch +refs/heads/branch_name:refs/remotes/origin/branch_name.
In fact, the new behavior has already run on our development project
https://gitlab.com/gitlab-org/gitlab-ce/pipelines and has no issues so far.
Issue 4097 was opened at the time
Workaround
Use HEAD when you want to push this to another remote.
deploy:
stage: deploy
script:
- git remote add heroku https://heroku:$HEROKU_API_KEY#git.heroku.com/<project>.git
- git push -f heroku HEAD:master
So don't push master. Push HEAD.
The OP Adam uses another workaround and add:
before_script:
- git checkout master

How to pull from specific branch in git- understanding gap

I am using gitlab and really confused in few things. :
When we create new branch by git checkout -b test. Does it create copy of master or it creates copy of branch i am currently in?
For example: I am currently at branch dev, then i write command git checkout -b test. So it will be copy of dev, not masters?
Pull : when we write git pull , it pulls changes of current branch from remote branch of same name. Its used when more people are working on same project.
Example : I am at branch dev, i write git pull, it updates my local as of dev in remote. Now i created a new branch test, checkout test branch and do git pull. It gives me :There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
its because there is no test branch in remote ?
What command to be used if i want to pull from dev branch while my current branch is test? is it git pull --rebase dev test?
When we write git push, it pushes current branch to remote one.
example : i am on branch test, i add, commit and write git push. It simply pushes my branch test to remote with same name as test.
Can we push to specific branch like push test to dev?
What is difference in following considering i am at branch test:
git push
git push origin test
they both push to remote?
My requirement is : there is branch dev which is not master branch, i am supposed to work on this branch as starting and end point. Like, new branch should be copy of this and i am supposed to push to same branch.
Does it create copy of master or it creates copy of branch i am currently in?
It creates a new branch named test based on the current branch, whatever that might be, as a starting point.
What command to be used if i want to pull from dev branch while my current branch is test?
I believe you can pull any branch you wish into your current branch. E.g. if you were on branch test and wanted to pull dev you could just use:
git pull origin dev
Can we push to specific branch like push test to dev?
Yes, can specify both the local and remote branch names when pushing, e.g.
git push origin test:dev
1- When you do git checkout -b test it creates copy of your current branch(in this case 'dev').
2- git pull will only sync your changes between remote and local. If you upload the branch and try to pull, it does not work because your local and remote changes will be synchronized.
3- This could help you : Make an existing Git branch track a remote branch?.
If you want to work in a copy of a branch, you should do this:
git checkout <origin_branch> (master, dev, what u want )
git checkout -b <work_branch> (test, for example. This create a copy of your origin branch)
After this, you have a new branch 'test' in your local repository. If you want to push this branch on the repo:
git add .
git commit -m "Pushing new branch test"
git --set-upstream origin <your_new_branch>

remote git repo cannot be auto checkout after a merge hook

I have a remote non-bare git repo, which is my static blog site.
I push a commit in local master branch to the remote master branch every time, and there is a post-update hook, which is like below:
echo "hook..."
git merge master
echo "after hook..."
In the remote repo, there is a pages branch which is checked out by default, what I want is that pages branch keep update of the master branch and auto checkout to workspace.
However, workspace cannot be checkout automatically, but the two branch has been updated.
In sum, What I want is the workspace can update after the pages branch merged every time. So that my website can update too.
==========detail process===========
==local repo:
*master
==remote repo:
*pages
master
git push local-master ---> remote-master [OK]
trigger hook do : git merge master to pages branch (which is checked out) [OK]
workspace updated (this is what I want) [NOT-OK]
Considering the current working directory of such an hook is the .git/ folder itself (ie, GIT_DIR is set to '.', which in non-bare repo is .git/), try a .git/hooks/post-receive with:
unset GIT_DIR
cd ..
git merge master

Resources