Pushing changes from a new machine to a github repository

时间:2015-12-14 17:58:12

标签: git github push git-push

  1. I had a git repository cloned (Machine1/.../Github/GitM1) on Machine 1 from my Github repository Git1.

  2. I copied the GitM1 folder (complete) on Machine 2.

  3. I ran the project (Machine2/.../Github/GitM1) on Machine 2 and made changes (~1MB) with nothing related to git (even git not installed)

  4. Now, I want to commit these changes to my Github repository Git1.

  5. How to do this (I prefer to do this via SSH key route)?

Thanks.

Edit : on using Jonathan's answer : I am getting this :

On pushing to git repository

On doing a pull asks me remove files (=50+) for merging. I am not sure if this is going in right direction.

1 个答案:

答案 0 :(得分:0)

On the "Machine2" copy of the repository...

First, add a remote to GitHub:

git remote add github _github url_

Next, push the change to GitHub:

git push github master

If on Machine2 you want the default remote to be GitHub (so you can just use "origin" rather than "github"), let's clobber any existing origin like this:

git remote remove origin
git remote add github _github url_

See "Working with remotes"

EDIT:

The "update were rejected..." error is because your master branch is behind the master branch on GitHub. Basically...you need to update your master branch.

There are several ways to do this, but a good way would be to rebase your changes on top of the changes on GitHub.

Follow these steps (assuming you set the github remote as above):

git fetch github
git rebase github/master

If there are any code-conflicts Git will tell you. Resolve the conflicts by editing the files and follow Git's instructions.

When you are done with these steps perform the push.