Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pushing only one folder to remote repo

Tags:

git

I'm using Git 1.7.4.1. I want to push commits I did on one folder to my remote repo. How do I push only changes from one folder to my remote repo? All the documentation I've found only lists how to push the entire repo ...

davea-mbp2:systems davea$ git push origin trunk
Password: 
To http://[email protected]/systems.git
 ! [rejected]        trunk -> trunk (non-fast-forward)
error: failed to push some refs to 'http://[email protected]/systems.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

The conflicts I'm being warned about do not apply to the folder that I want to push. Any help is appreciated, - Dave

like image 248
Dave Avatar asked May 03 '11 13:05

Dave


People also ask

How do I push a specific folder in GitHub?

Open Git Bash in that particular folder that you want to push. Type git remote add origin PASTE_SSH_KEY_OF_CREATED_REPO. Then type git push origin master –force (type 'main' in place of the 'master' if your default branch is master).


2 Answers

Git works by pushing entire commits. Either rebase interactively to isolate your changes to the directory you are interested in., or make a submodule for it.

like image 55
Adam Dymitruk Avatar answered Sep 28 '22 02:09

Adam Dymitruk


Git is not like subversion. The short answer is, you can't.

You should consider rebasing your change (only the one relevant) against the remote

git rebase -i origin/trunk

should get you underway. Be sure to read the comments and instructions along the way. There is also man git-rebase of course.

In the end, when you are satisfied with the result, you can either create a new branch from there

 git checkout -b rebased HEAD

or you can opt to make it your new master. I'll leave it up to you how to manage your branches locally (because you didn't tell us about them).

Pushing woud then be easy with

 git push origin trunk
like image 32
sehe Avatar answered Sep 28 '22 01:09

sehe