Reputation: 1971
I have a remote Git repository, which is a folder containing a bunch of files.
I have just created a new file on my computer, without pulling the existing Git repository or anything. Can I push this new file such that it ends up in the folder I have in the remote repository?
Or do I have to pull
first, add my file, and then push
again.
(The file does not need to work with any of the other files in the folder)
Upvotes: 5
Views: 38933
Reputation: 1630
You can push by force after doing a git add and a commit without doing a pull. Not recommended but here you go
git push -f origin your-branch
Note: Lot of organizations don't allow force pushing and you might get some custom error.
remote: Force-pushing to this repository has been disabled
Upvotes: -1
Reputation: 1127
TLDR; No
|| Explanation: To communicate with the remote git repo you need to link it with a folder in your local machine (git init
). After this, add the remote repo link (git remote add origin <URL>
) and pull it (git pull origin master
). Now, once your local folder is synchronized with the remote repo you're free to add any new files (git add <file>
, git commit -m <message>
and git push origin master
). This would be the simplest way to do it. Remember, git stores all the information in your that local folder (in .git/ folder) which you just linked with the remote repo and its responsibility is to maintain all git metadata (credentials, git history...). Without this process in place, it would be difficult for git to track historical information about the project. I hope you understand the reason behind this.
Upvotes: 13
Reputation: 116
Simply place the local file into existing repository the run the following commands git add --all git commit git push
Upvotes: 1
Reputation: 45649
Your local repo communicates to a remote repo in terms of commits (snapshots of the entire content). Only within those commits do they discuss individual files.
You have to clone (or otherwise link a local repo to the remote), check out the branch to which you will add the file, copy the file into the work tree, add, commit, and push.
Upvotes: 1