IT story

Github에서 새 코드 푸시 문제

hot-time 2020. 6. 20. 09:35
반응형

Github에서 새 코드 푸시 문제


Readme.md 파일 만있는 Github에 새로운 저장소를 만들었습니다.

이 리포지토리로 푸시하려는 RoR 프로젝트를 새로 만들었습니다. 다음은 내가 받고있는 오류와 함께 이것을 실행하기 위해 터미널에서 준 명령입니다.

git remote add origin https://github.com/aniruddhabarapatre/learn-rails.git

그 후 내 사용자 이름과 비밀번호를 입력했습니다

git push -u origin master

오류 ---

To https://github.com/aniruddhabarapatre/learn-rails.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/aniruddhabarapatre/learn-rails.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

코드를 Github 저장소로 푸시 한 것은 이번이 처음이며 오류로 인해 길을 잃었습니다. 여기에서 묻는 몇 가지 다른 질문을 검색했지만 처음에는 문제가 없었습니다.


사용자가 만든 때 GitHub의에 저장소를 , 당신은 생성 README.md 이며, A는 새로운 커밋을 .

로컬 저장소는이 커밋에 대해 아직 모릅니다. 그 후:

원격에 로컬에없는 작업이 포함되어있어 업데이트가 거부되었습니다.

이 조언을 따르고 싶을 수도 있습니다.

git pull다시 변경 하기 전에 먼저 원격 변경 사항 (예 : ' ')을 병합 할 수 있습니다 .

그건:

git pull
# Fix any merge conflicts, if you have a `README.md` locally
git push -u origin master

이것이 첫 번째 푸시 인 경우

그냥 변경

git push **-u** origin master

이렇게 바꾸세요!

git push -f origin master

⚡️ EASY : 필요한 것은 강요입니다. readme.mdGithub에서 파일을 만들었을 수도 있고 아직 가져 오지 않았기 때문입니다.

git push -f origin master

그리고 여기 GIF가 있습니다.

git push -f origin 마스터

주의 :를 사용 force하면 동일한 프로젝트에서 다른 사람들의 기록을 변경할 수 있습니다. 기본적으로 모든 사람이 파일을 삭제하는 것에 신경 쓰지 않는다면 계속 진행하십시오. 특히 당신이 프로젝트의 유일한 개발자라면.


다음 명령으로 강제 푸시를 실행하십시오.

git push -f origin master

github에서 제공하는 인터페이스를 통해 Readme.md 파일을 추가했다고 가정하면 readme는 아직 로컬 폴더에 없습니다. 따라서 원격 리포지토리로 푸시하려고하면 로컬 리포지토리에 readme 파일이 없기 때문에 오류가 발생합니다. "시간이 지남"입니다. 따라서 오류 메시지에 제시된대로 "git pull"을 먼저 시도하십시오. 이것은 원격 저장소에서 readme를 가져와 로컬 디렉토리와 병합합니다. 그 후에는 원격 저장소로 푸시하는 데 아무런 문제가 없습니다 (게시 한 명령은 나에게 유효합니다).


한동안 변경 사항을 커밋하지 않은 경우이를 고려하면 효과가있을 수 있습니다.

git add files
git commit -m "Your Commit"
git push -u origin master

그것은 나를 위해 일했지만 희망은 당신도 마찬가지입니다.


This is happen when you try to push initially.Because in your GitHub repo have readMe.md or any other new thing which is not in your local repo. First you have to merge unrelated history of your github repo.To do that

git pull origin master --allow-unrelated-histories

then you can get the other files from repo(readMe.md or any)using this

git pull origin master

After that

git push -u origin master

Now you successfully push your all the changes into Github repo.I'm not expert in git but every time these step work for me.


if you use the git for mac in GUI you can chose Respository->Pull or the "comm+shift+p" to "git pull" first, then publish the source.


This error occurs when you push the data from your local directory to your remote git repository by following git command: git push -u origin master

As local directory and git remote directory's files conflicted.

Solution :

After committing all files to staging follow below steps.

  1. Fetch the files from the remote repository as its conflict with the local working directory.

    • git pull <remoter-url> <branch-name>
  2. Commit the changes again.

    • git add -A
    • git commit -m ‘<comment>'
  3. After committed merge files with both directory you can use

    • git push -u origin master

This will fix the issue. Thanks.


I had a similar problem... I resolved it like this (i'm not an git expert so i don't know if it is a right solution, but it worked for me):

git pull origin master --allow-unrelated-histories
git merge origin origin/master
git rm README.md
git commit -m 'removed readme.md'
git push origin master

I struggled with this error for more than an hour! Below is what helped me resolve it. All this while my working directory was the repo i had cloned on my system.

If you are doing adding files to your existing repository** 1. I pulled everything which I had added to my repository to my GitHub folder:

git pull


Output was- some readme file file1 file2

  1. I copied (drag and drop) my new files (the files which I wanted to push) to my cloned repository (GitHub repo). When you will ls this repo you should see your old and new files.

eg. some readme file file1 file2 newfile1 newfile2

  1. git add "newfile1" "newfile2"

  2. [optional] git status this will assure you if the files you want to add are staged properly or not output was


On branch master Your branch is up-to-date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage)

    new file:   newfile1
    new file:   newfile2

5.git commit -m "whatever description you want to give" 6.git push

And all my new files along with the older ones were seen in my repo.


A simpler answer is to manually upload the README.MD file from your computer to GitHub. Worked very well for me.


지점 옵션을 사용하고 "원격 / 원점"폴더를 마우스 오른쪽 단추로 클릭 한 다음 "원격에서 지점 삭제"를 클릭하십시오 (아래 이미지 참조).

이미지

참고 URL : https://stackoverflow.com/questions/20939648/issue-pushing-new-code-in-github

반응형