Adding subdirectories in existing git repository
You have done
git push but the new folders didn’t got pushed. What happened?
Having new folders and subfolders in the git repository, but the files under those not showing in the server?
Adding subdirectories in existing git repositories should have been direct right? But, sometimes it is not. I will show you How to add subdirectory in existing git repository
Let’s say you have existing git repository
my-git-repo and you want to add new folder under it:
Step by steps to add git subdirectories in existing git repository
1. Create folder in the repository you are going to create new folders
mkdir -p new-folder/another-sub-folder
2. Now if you do
git status you will see the new folder under new listing.
3. Create a file under another-sub-folder otherwise git won’t show nothing.
cd new-folder/another-sub-folder && touch some-file.xml
4. Go to another-sub-folder and issue
5. Now go back to the root of the folder and issue
git add new-folder/
6. You are done, when you do
git status you will see your new files being listed for commit.
asked to pull from remote but did not specify the branch github error
Mostly, you got a new repository or even existing one and you are trying to interact with it.
The above problem would be happening this time.
Git would allow you to have many branches of the same repository. So when you try to interact with the repository and you didn’t specify which branch then this would be the problem.
Because this is not the default configured remote
for your current branch, you must specify a branch on the command line
The tasks you are trying to do might be
git push or even others.
The first thing you want to do would be to check what branch you are in.
If you see master in there * master then do
git pull origin master
This would take care of the problem
You can remove the file from the local cache first and push that
git rm --cached /file/to/be/removed/from/cache
Then do the status to see the delete has taken place
You will see something like
Then push the change
Also you might get something like
fatal: Pathspec ‘some.file.name.goes.here’ is in submodule ‘some/folder/name’
Also you might notice, if you commit and pushed, only some skeleton of the of the folder structure without the actual files would be committed.
The root of the problem is the folder you are trying to add is tracked under git itself.
This would confuse git and would rather leave it up to you.
First go ahead and remove the .git folder in the new directory
sudo rm -rf /path/to/new/folder/.git
Then clear the cache from git memory of the new folder
git rm -r --cache /path/to/new/folder
Then when you do the
you will see all the new files being listed and you can commit that.
Installing CLI gems will be through yum, so for the case of the git it will be:
sudo yum install git
On git and want to see the changes on files after you stage it?
git diff --cached file-to-check
Also if you want to see the difference of hte file with repo
git diff HEAD file-to-check
Was trying to pull something to github and noticed I was using a bit old Git version.
Then I went to and downloaded for mac.
After installing, I checked if I have the latest version by doing
and it showed
git version 22.214.171.124
Then I suspected the previous one is not updated and checked which git binary is being used
And it replied as
The new one is being save on another directory – /usr/local/git
Then I checked how my path is setup
it was something like
As you can see the poor mac would see the /usr/bin first to check if command binary is inside it and it would continue.. so it was not checking the /usr/local/git..
Just putting the proper path infront of the path would solve the problem
That would fix the problem. In the mean time, doing some cleanup on the existing git files would help also..