Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I have problems pushing new branches to my Git repository?

As a followup to my question about unavailable branches after svn to git migration, I have a different problem: I'm unable to push new branches to my central Git repository.

$ git clone ssh://server/opt/git/our_app.git
$ cd our_app
$ git branch my-test-branch
$ git checkout my-test-branch
$ echo test > test.txt
$ git add test.txt
$ git commit test.txt -m "test commit"
[master ed81ec0] test commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 test.txt
$ git push
Everything up-to-date

So, this does not push my branch to the server. A colleague advised me to look into my .git/config, which looks like this:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://server/opt/git/our_app.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

I was adviced to manually add a push entry:

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = ssh://server/opt/git/our_app.git
    push = refs/heads/*:refs/heads/*

Now things looked better:

$ git push
Password: 
Counting objects: 1, done.
Delta compression using up to 1 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (1/1), 5 bytes, done.
Total 1 (delta 1), reused 0 (delta 0)
To ssh://server/opt/git/our_app.git
 * [new branch]      my-test-branch -> my-test-branch

While this worked, it still feels like a hack. What's the proper way to do this?

like image 840
neu242 Avatar asked Oct 25 '10 07:10

neu242


People also ask

Why is my git push failing?

This error mainly occurs when you attempt to push your local changes to GitHub while the local repository (repo) has not yet been updated with any changes made in the remote repo. So Git is trying to tell you to update the local repo with the current changes in the remote before pushing your own changes.

Why is GitHub rejecting my push?

Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused. If another person has pushed to the same branch as you, Git won't be able to push your changes: $ git push origin main > To https://github.com/USERNAME/REPOSITORY.git > !

What are the issues when git push doesn't work?

You need to use git pull and resolve the difference between your local changes and the remote changes before you can git push . There is still a commit in the remote branch initializing the repo that may not be in your local version.


2 Answers

To push a new branch use git push origin my-test-branch

like image 137
abyx Avatar answered Nov 15 '22 03:11

abyx


If you just want to push your branch with the same branch name then just use

git push origin my-test-branch

If you want your changes to appear on the master branch of the origin repo:

git push origin my-test-branch:master
like image 25
Dipstick Avatar answered Nov 15 '22 03:11

Dipstick