A
A
AlexeySmk2020-09-17 17:35:17
git
AlexeySmk, 2020-09-17 17:35:17

How, in my case, to push a file from a local to a remote Git repository to another branch?

Good day!
I have a remote repository (let's call it *test*) which contains a master branch, gh-pages and an additional branch that comes from the gh-pages branch. I need to push a file from my local repository to a remote one in the additional branch. How can this be done?

Step by step I will expand my procedure:
1. Initialize the local repository:
git init

2. Add the file to be pushed to the index:
git add "index.html"

3. Make a commit:
git commit -m "add new sections"

4. Connect to the remote repository:

git remote add origin https://github.com/github-name/test.git


5. I'm trying to push a commit to the additional branch and I get an error:
git push origin additional
=> error: src refspec additional does not match any
=> error: failed to push some refs to 'https://github.com/AlexeySmk/rsschool-cv.git'


5. I try to switch to the branch where I need to push the commit and try to push it again:
git checkout -b additional
=> Switched to a new branch 'additional'
git push origin additional


and I get the following error:
! [rejected]        additional -> additional (fetch first)
error: failed to push some refs to 'https://github.com/github-name/test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


I will be grateful for the answer!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Steppp, 2020-09-17
@Steppp

5) git push origin master

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question