简体   繁体   中英

How to push inside a Github repository using the terminal?

I'm trying to make push inside an existing repository in Github using the following command,

    git push -u origin master

I get the following errors,

    To https://github.com/Chaklader/Technical-Interview.git
! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/Chaklader/Technical-Interview.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

AS it suggested, I tried to make a pull using the following command,

git pull origin master

That seems doesn't work either. How to resolve the issue ?

I made a silly mistake and had no commit in the Github and thus the problem started.

git commit -m "added some examples for the design patterns (Observer, Visitors, Proxy etc)"

Afterwards, there was no issue with the push command.

Your local master branch is behind the remote branch.

before adding local changes .first sync with remote using

git pull

(check using git log --oneline ) .It should match with remote changes yourmaster branch log like this now.

a570f1e design aptterns
607f53c added different deign patterns
c586b42 Update mySyntax.cpp
17ffb35 Update README.md
66e75d3 Update README.md
e66d701 update
3344773 first commit
0bd776c first commit
c1a0898 first commit
2468750 first commit

on top of above commit your local changes .then push using (push to remote master branch)

git push origin HEAD:refs/for/master

You can reset your changed files and stash them at first:

git rest HEAD^
git stash

Then pull from remote repository:

git pull

Then pop up stashed files:

git stash pop

Then add all files and commit and push to remote repository.

git add .
git push origin master

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM