After pushing from my git sandbox to my remote repository, why does the file shows up as deleted in the remote repository?

15 views (last 30 days)
If I add a file in a local repository, commit this file and push it up to the remote repository, this file does not appear in the "Project Files" of the remote repository. The file can be found in the "Modified Files" list, but its status is "deleted". Commiting in the remote repository then deletes the file in the remote, but the file is still in my local copy!
How can I successfully push and fetch files between a local and remote copy?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 19 Nov 2014
This behaviour is observed when both the local and remote repositories have working directories. 
If you create a GIT repository with a working directory you should be able to see your files in it, and commit, push and fetch.
So for example this behaviour can be reproduced with these steps:
  1. Create a repository, let's call it "ProjectA", add some files, make some commits.
  2. Clone this to another repository, "ProjectB", by setting ProjectB's "Repository Path" to ProjectA.
ProjectB is initially exactly the same as ProjectA, but pushing and fetching produces inconsistencies between the two.
This workflow of cloning an existing working git repository is not best practice with git, which is why it gives this strange behaviour.
The best practice is to create a "bare" git repository for your remote. This is a repository for keeping a master copy of all the source history, but does not have a working directory.
All working copies of your project should use this bare repository as its remote repository. They all push and fetch from the bare, and any conflicts that occur can be resolved when pushing or fetching from the shared location.
In a bare repository you will not see your files, but a file structure like this:
If you open the ".git" folder in a working repository you will see the same files. These contain all the source control changes and history.
In Simulink Project it is possible to create a bare repository and a working copy at the same time:
  1. In the HOME ribbon select New > Simulink Project > From Source Control
2. When setting the repository path, click the "Change..." button.
3. In the "Select A Repository" Window that opens click the + button and select a folder for keeping the bare repository in.
4. Click Retrieve and then "Yes" when it asks if you want to create a new project.
5. Click "Create" to create the project.
This will create a bare repository in the folder selected in step 3, and a working copy of the bare repository wherever you created the simulink project.
If you want to create more working copies of your project, you should set the repository path to be the bare repository. All the working copies will consequently push and fetch changes to/from the bare repository. This is the standard workflow with git.

More Answers (0)

Categories

Find more on Source Control in Projects in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!