I developed a project that was been developed by another developers. I sent my code to the previous developers to make changes in their code but they said that they have never worked with git, so they added changes to the project and it is now the actual version but not under version control.
So, I already have commits in github and I need to push this new version.
What I did:
git init
git remote add origin
git add .
git push origin master
But there is an problem: I can't push new changes before updating the local repo. If I update my repo it will return all the files that the previous developers have deleted.
How do I push the current version without pulling data from git?
No, you must make a commit before you can push. What is being pushed is the commit (or commits).
Always Pull Before a Push Doing so will ensure that your local copy is in sync with the remote repository. Remember, other people have been pushing to the remote copy, and if you push before syncing up, you could end up with multiple heads or merge conflicts when you push.
Updating a file on a repo you don't own. Once you click Propose file change, a pull request will be created and the owner of the repository will have a chance to review your change and either accept it, reject it, or discuss it with you.
You can do a forced push.
git push -f origin branch_name
The forced push will erase all commit history of the remote repository's branch, and replace it to your branch.
Check the answers for doing forced pushes in "How do I properly force a Git push?". Forced push can have unintended consequences as mentioned in "Git: How to ignore fast forward and revert origin [branch] to earlier commit?", so check for the same.
The forced push will be an incorrect way to push stuff in your case, since you already have previous commits on GitHub, and this will erase the commit history for previous commits.
Hence, to preserve your commit history, you can do the following things:
Remove all the files from the git repository, and then add the new files here, and then commit the updated files:
git rm -rf . cp -r path/to/updated/code/* . git add .
Doing a git status
now will tell you which files the other developers modified, and a git diff
will show what modifications are there.
If a file has remain unchanged, then git rm
and git add
will nullify the effect of each other.
The files which those developers deleted remain deleted since you ran the git rm
for them but no git add
.
Once you are satisfied that these indeed are the changes, you can commit using
git commit -m "Merged new code"
Potential gotchas:
git rm -rf .
(and similarly .gitattributes
and other such files). Reset HEAD for each such files using git reset HEAD .gitignore
before the commit.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With