how to sync a "shadow" git repository with a main repository "secretly" - linux

I have a client that I do work for via a git repository. I do not want for him to know that I am partly using another developer. I have therefore created a "shadow" repository, that my developer is using.
How to sync the "shadow" repository with the main repository so that the main repository does not know that this is happening?
I cannot merge with a git command, since this will reveal what I really have done.
I could copy and paste all files, but that would visible in git that I have deleted all files and replaced with new files with the same name. That does not look good.
My client is using bitbucket. I could give the other developer my bitbucket login, but I would want to avoid to do that.
What actually work, is that I can open a file in the main repository, delete the content and then paste in the updated code. Then I could commit and it would look is if I had done the work directly in the main repository. But this is time-consuming (and time is something I do not have too much of).
Is there a different way that I could "secretly" copy the content of files from the shadow repository to the main repository? Is there a linux/osx-command I could use that replaces the content of a file without deleting and recreating the file (which I then could use recursively)? Is there a git-command that make this possible without leaving a trail of evidence of what I have actually done?

you can have the same set of local files revisioned by different git repositories, using the command line. Just use the GIT_DIR environment variable. The Git repositories are completely independent, and can track files from the same directory.
rem set Git to use the sub-developer's git repository
set GIT_DIR=/path/to/sub/repository.com
rem verify which repository that you are on
git rev-parse --git-dir
rem pull the sub-developer's latest
git pull
rem merge, commit, change, push, change branches, whatever
rem ... when the code is the way you want it
rem switch to client repository
set GIT_DIR=/path/to/client/repository.com
rem bring main repository up to date
git commit -m"changes brought over from sub-developer"
rem push the updated code to the client repository
git push
this is useful for other development practices, like versioning lab data, local developmental utilities, work logs, and other 'misc' files that seem to accumulate with the source code, but shouldn't be archived with it.

After my error on the first answer, I feel compelled to try again.
try reading in the sub developer branch and comparing/merging to main with git differencing. see 'git help config' for 'diff.external'. I use diffuse.exe and a batch file to map the parameters.
The work flow would look something like this.
rem make a remote to the sub
git remote add MYSUB https://path/to/sub/repository.com
rem see what branches are there
git remote show MYSUB
rem get the branch from the subdeveloper
git fetch MYSUB CurBranch:CurBranch
rem view/manually merge just the modified files
git diff --diff-filter=M MYSUB/CurBranch
rem cleanup
git branch -D MYSUB/CurBranch
git rm MYSUB
rem push to main site
git push
This is the method I use to transfer branches to my lab machine, via a USB memory stick. I have not tried it with a remote connection.

Related

How to go back to the Working Directory that was not committed

I forgot to commit on the directory where I was working and then I checkout to the previous commit and now I want to back to the directory where I used to work. What can i do ?
If your checkout of the previous version somehow deleted your folder, which was not added/committed, then you would need to rely on a file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?", or on your IDE. Some of them keep a local history (IntelliJ IDEA, VSCode through an extension, ...): you might get back some of your files content that way.
In the end, it depends on the exact git checkout command you did, considering this command can update files and/or branches.
That is why it is recommanded to use git switch (branch only) or git restore (files only), instead of git checkout.

Backup options for a project under version control with Git

I just arrived in a company which does not have access to GitHub or similar.
I was wondering about ways to backup my code using the private OneDrive which is given to each employee.
I just thought of moving my folder from the "document" directory to the "OneDrive" directory. But I was wondering whether changing the path will break my code.
Will it preserve the .git directory? Should I rerun git init (loosing the past history)?
You can move a Git repository from one path to another without affecting it. A Git repo is a self-contained entity (with the exception of global Git config) and the .git folder containing all Git files is just like any other folder (so it can be moved, deleted, etc.).
If you want to use OneDrive as a backup, there are better options than simply copying your project over. Tools like restic or similar would allow you to keep your backup up to date in an efficient way.
Note that you can also set OneDrive as a Git remote. Since it sounds like you are missing options such as GitHub or Bitbucket for your company, this is probably your best option.
To add a remote called onedrive on OneDrive, you can run:
git init --bare ~/OneDrive/<project>.git
git remote add onedrive ~/OneDrive/<project>.git
And then you can use onedrive as you would any other remote. For instance:
git push --set-upstream onedrive master

Failsafe Automated Git Update/Add/Commit

I have a website that I need to commit system generated files and folders to an existing git repository via linux command line. I have an automated process that monitors a folder for new bash scripts and runs them. The website creates the scripts and saves them to the folder.
I keep getting issues where something has changed on either the remote repo or my local one that is stopping git from completing the following commands
git pull --rebase origin
git add [repo path to updated file(s)]/*
git commit -m "commit message"
git push master
I need to bullet proof this process so that it will just run and I can forget about it. Right now, permissions issues on files pulled down, or merge conflicts, etc... keep getting the repo out of sync. How can I bullet proof the commands above so they will pull down any remote changes and then commit any new ones necessary?

Handling line endings for git

Here is what I messed up so far,
I copied (not cloned) a rails project from windows to linux pc
Then created a new branch and made lots of changes
At last commited twice whole project and pushed it to a remote repository with windows line endings.
Problem: so my problem is that, since I copied the project from windows to linux, when I run git status whole project shows modified. I don't see the changes I made specifically. Since I committed and pushed whole project, I lost history of files change.
What is needed: So I want to remove my last two commit but I want to keep my changes that I made. Then I want to convert the line endings from windows to unix of whole project so that when I run git status I see only the files that I changed, not whole project. And then I want to commit and push to remote.
It would be nice if there is a solution for this mess.
I am not sure if this will be helpful, I am working on a rails project and my IDE is rubymine.
To undo your last two commits run this:
git reset --soft HEAD~2. This will put the files involved in the commits into your working directory.
Run git status and they will show as staged changes (ready for commit).
Edit your files.
Stage and commit your changes. Important: Don't push
Run git pull.
Run git push
Make sure you commit your changes and do a git pull prior to git push, otherwise your attempt to push will cause conflict and will be rejected.
You can use git filter-branch.
Similar question here.

Git - Syncing a Github repo with a local one?

First off, forgive me if this is a duplicate question. I don't know anything but the basic terminology, and it's difficult to find an answer just using laymen's terms.
I made a project, and I made a repository on Github. I've been able to work with that and upload stuff to it for some time, on Windows. The Github Windows application is nice, but I wish there was a GUI for the Linux git.
I want to be able to download the source for this project, and be able to edit it on my Linux machine, and be able to do git commit -m 'durrhurr' and have it upload it to the master repository.
Forgive me if you've already done most of this:
The first step is to set up your ssh keys if you are trying to go through ssh, if you are going through https you can skip this step. Detailed instructions are provided at https://help.github.com/articles/generating-ssh-keys
The next step is to make a local clone of the repository. Using the command line it will be git clone <url> The url you should be able to find on your github page.
After that you should be able to commit and push over the command line using git commit -am "commit message" and git push
You can use SmartGit for a GUI for git on Linux: http://www.syntevo.com/smartgit/index.html
But learning git first on the command line is generally a good idea:
Below are some basic examples assuming you are only working from the master branch:
Example for starting a local repo based on what you have from github:
git clone https://github.com/sampson-chen/sack.git
To see the status of the repo, do:
git status
Example for syncing your local repo to more recent changes on github:
git pull
Example for adding new or modified files to a "stage" for commit
git add /path/file1 /path/file2
Think of the stage as the files that you explicitly tell git to keep track of for revision control. git will see the all the files in the repo (and changes to tracked files), but it will only do work on the files that you add to a stage to be committed.
Example for committing the files in your "stage"
git commit
Example for pushing your local repo (whatever you have committed to your local repo) to github
git push
What you need to do is clone your git repository. From terminal cd to the directory you want the project in and do
git clone https://github.com/[username]/[repository].git
Remember not to use sudo as you will mess up the remote permissions.
You then need to commit any changes locally, i.e your git commit -m and then you can do.
git push
This will update the remote repository.
Lastly if you need to update your local project cd to the required directory and then:
git pull
To start working on the project in linux, clone the repo to linux machine. Add the ssh public key to github. Add your username and email to git-config.
For GUI you can use gitg.
PS : Get used to git cli, It is worth to spend time on it.

Resources