Search code examples
gitgithubrepositorygit-branchgit-pull

git err :: Can't create remote/branch


I have problem to push to my github. I've uploaded other projects on github. but suddenly, problem appears.

In terminal, I run following:

1. git clone https://github.com/(username)/(reponame).git  
2. create remote to my github repogisry address.
3. git init  
4. git add .
5. git commit -m "message"
6. git push <repo> <branch>

but there's this message

"Cant's push refs to remote, Try running 'pull' to integrate your changes.

so I pull ->

git pull <remote name> <branch>

but there's other error :

fatal: couldn't find remote ref master

I checked out my folder. In .git/refs there's no 'remotes' folder which has remote, branch. but in VSCODE (when I run push to) there's in popup I/'ve created.
To solve this error, deleted remote, create again, git init again, restart vscode, but the error isn't fixed.

To test the other, I create other project, different github repo. this project works.(in this project's folder the remotes folder is in refs)

but the project problems appeared before still has err.

how to solve this problem? Please help..


Solution

  • The steps to clone a git-repo and then add a new branch remote are as follows:

    1. git clone https://server.name/git/testing.git
    2. git checkout -b <branch-name> # create locally branch and checked out
    3. git push <remote-name> <branch-name> # push local branch to remote

    So do not create a new git repo (git init) after clone, because git clone makes a git init in his workflow Do I need to do 'git init' before doing 'git clone' on a project

    Look also at this documentation