Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a single file in a subdirectory to Github (not master)

I have changed a single file in a subdirectory of my repository and I want to push just that file to Github.

I've made a small change to one file, and I don't want to re-upload the entire repository.

It seems like all of the instructions that I've seen so far require me to merge locally with the master and then push my local master to the remote origin.

How can I push just that one file?

like image 316
moon star Avatar asked Nov 20 '12 18:11

moon star


People also ask

How do I push a branch instead of master?

In order to push a Git branch to remote, you need to execute the “git push” command and specify the remote as well as the branch name to be pushed. If you are not already on the branch that you want to push, you can execute the “git checkout” command to switch to your branch.

How do I restrict push to master on GitHub?

To find it go to Settings > Branches > Branch Protection Rules and click 'Add Rule'. Then, enter the name of the branch you want to protect and click the checkbox to require pull request reviews before merging.

How do I push subfolders to GitHub?

initialize a new repo to serve as the child repo. move everything from the subdirectory of the parent repo work tree to the child repo work tree. commit the child repo. replace the subdirectory in the parent repo with a submodule reference.


1 Answers

When you do a push, git only takes the changes that you have committed.

Remember when you do a git status it shows you the files you changed since the last push?

Once you commit those changes and do a push they are the only files that get pushed so you don't have to worry about thinking that the entire master gets pushed because in reality it does not.

How to push a single file:

git commit yourfile.js git status git push origin master 
like image 142
krilovich Avatar answered Oct 06 '22 22:10

krilovich