Working with two repos and two projects in Git - linux

I'm new to Git, and i want to push some files to one repo and other files to another repo, but when i do the second push it goes with the files of the first repo. How can i push the the files separately?

Should you have .git directories in each your project directories. And don't forget for use git bash inside directories what you want to push. Example:
Project A in
C:/projectA
inside projectA you have .git directories(hidden files)
Project B in
C:/projectB
inside projectB you have .git directories(hidden files)
for push project A, try this
cd c:
cd projectA
you stay in projectA, and then push.

Related

How to connect two separate folders into the same GitHub repository?

I have already made a GitHub repository with a folder1, but I have a ../etc/etc/folder2 that I would like to add into the same repository because they both are a part of the same project.
As you can see these two folders are not super close to each other, but they are in the same linux file system. How can I add folder2 to my existing GitHub repository that contains folder1?
What I ended up doing was creating the repository in the root directory.
I created a .gitignore file to ignore all files except the two folders that I wanted in the repository.
## Ignore everything...
*
## Except...
folder1
folder1/*
path/to/folder2
path/to/folder2/*
You would need to, locally on your Linux machine, move or copy the folder2 in your local cloned repository, add and commit.
Then you can push, in order to see folder2 in your remote GitHub repository.
The alternative is:
make a Git repository in ../etc/etc/folder2, push it to a separate GitHub repo folder2
reference the remote GitHub repository folder2 as a submodule in your first local cloned repository
That is:
cd /path/to/folder1
git submodule add -b main -- https://github.com/<me>/folder2
That way, you have the repo folder2 referenced by your main repository.
If you change anything in folder2 (original path), add, commit and push.
Then, from the first local cloned repository, git submodule update --remote is enough to update the folder2 submodule content.

GitHub shows a submodule instead of a subfolder

Git unconsciously created submodule from my subfolder where there was .git lately. I deleted .git and there's no git files like .gitignore but still can't add files to this subfolder. It looks like this
And inside io-invoices (submodule) I've got
I've checked hidden files.
You probably need to remove that directory from the Git tree and re-add it later. Backup everything before!
git rm --cached ./io-invoices
git add ./io-invoices

git on Linux uploading files from another repository too

I have 2 git repositories, one with 3 files and another one with the same 3 files but similar content. (Like README.md, index.html, etc.)
I used "git add" to add the files and created 2 remotes named "view" and "music".
I added the 3 first files in the first folder with "git add" and commited+pushed them to the view repository.
Then I went to the other folder, added those 3 files with "git add" too and commit+pushed them too, but i suddenly have the other 3 files pushed too.
(The repository "music" has the files from "view" too)
TL;DR: How can I seperate git repositories on Linux
Running CentOS 7 and the newest git update available via yum.
I already tried making 2 different folders and writing "git init" before using the "git add" and other commands to commit + push.
They still returned an error instead of posting duplicates.
The following was used in both folders, but errors happened on the second folder
echo "# testing" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git#github.Username/reponame.git
git push -u origin master
I expected that git would somehow distinguish between multiple repositories, and that I can simply have 2 folders with 2 repositories.
I thought after a git push / commit the "git add array" of files would be empty again and I could add new files for another git commit / push.
How can I commit/push to multiple repositories via the Linux Command Line and push different files to different repositores without them getting mixed up.
EDIT:
The folder structure is as follows:
[usr#servr~]$ ls music/
index.html README.md songs
[usr#servr~]$ ls view/
index.html README.md pics
The exact steps I did:
cd music
git init; git add README.md; git add index.html; git add songs
git commit -m "Initial Commit"; git remote add origin <link2music>; git push -u music master
cd ../view
git add README.md; git add index.html; git add songs; git commit -m "Initial Commit"; git remote add origin <link2view>; git push -u view master
Then the git repository of view suddenly had the README.md of the music repository, and the folder songs too (even though it shouldnt).
I deleted the view repository but kept the music repository on github. (No folder deleted on my Linux machine). I then tried to exactly enter the code from the first snippet (the github offical one) in both folders (with git init too in each folder) and now the music repository, which already existed, threw me the error "! [rejected] master -> master (fetch first)", even though i never deleted the music repository, neither from my machine nor from github. (files are the same on both)
Someone recommended me to try git status, and with that I found out that my problem was the upper-level folder. I accidentally made the upper level folder, above my 2 "repo"-folders, a git repository.
How it should be:
Home
->music(repo .git)
->view(repo .git)
Hot it was (bad):
Home (repo .git)
->music
->view
That means that I didn't push the 2 folders to their respective repositories, but I instead pushed the upper-level folder (my home folder) to the repositories, which of course contained both of my other folders.
I deleted the .git folder from my home, cloned my git repos in a different folder again, and now they work as intended.

Moving git repo from public_html/stage folder to root public_html/

On my linux server I have a website running in public_html/stage which i cloned from guthub to /stage folder.
Now after the development is over i want to move this folder to root i.e public_html folder, making sure that its sync with my repo.
I tried to cp all /stage files to the root directory but the main folder /app was not copied.
Pls guide me how can I move this staging to production.
Also please let me know what is the standard way of doing this?
They're just files, you can copy them.
cd /path/to/public_html
cp -r stage/* .
Make sure not to copy your Git repository, the .git directory. If you did, that would turn public_html/ into a Git repository.
If you do want to move the whole repository into public_html, again it's just files. Everything git needs is in stage/.git/.
I got the solution to my problem, but not sure if what I did is a standard way. But anyhow it resolved my problem. So here is what i did...
I initialized an empty repo in public_html folder and then added remote to my github repo and finally fetch all code from the repo.
$ git init
$ git remote add origin https://github.com/user/repo.git
$ git fetch --all
$ git reset --hard origin/master
So now my project is working fine at the root of the website and is in sync with the repo. So everytime I do some local changes to my repo I only need to pull them from repo
$ git pull origin master
And thats all!

Is there a way to git clone multiple .git repositories at one shot, all exisiting in same folder in remote machine?

I have a git machine, where there is a folder: git:/opt/git/third_party>
Inside third_party there are multiple .git repoitories.
I wish to clone all the .git inside third_party at one shot:
Something like:
git clone kingsmasher1#git:/opt/git/third_party/*.git
Is it possible?
Alternative approach
You can use mr tool. With mr you can specify a file, where you list all of your repositories. Via mr checkout you'll clone all configured repos and with mr update you'll update all of them etc.

Resources