0

I am creating (on a personal local server) a git server where I will upload all my projects inside. The structure will be as follows:

myprojects
    dir_project1
    dir_project2
    ....

Now I'm wondering, how do i upload all my projects inside that folder? And then, for each project that i will create, i will have to login to the server, create the project folder, type git init --bare and then (from my PC) upload. Is there a way where I can do the git push directly, without going into the server and creating (every time) the folders of every single project that I will do (and launch command git init --bare)?

Thanks

1 Answer 1

0

I'm thinking you need to use the git clone <dir_project1> command to first clone your master project and use git checkout -b <new_branch_name> to create a new branch and work on the cloned project file with that branch selected.

To check what branch is selected run git checkout this will list all available branches (the asterisk will indicate which branch you are currently working in)

Once you have checked out the new branch you may begin to make changes to your project directory. All changes done now are being done via the branch you have just created. That way you won't modify your master branch until you have tested and are 100% positive you want to commit/merge your changes to the master branch. (we will get to this part towards the end)

Once you have modified the directory in some way (adding a file or modifying and existing file/directory) use the git add <insert_file_here.txt> command to allow git to understand that you have made changes to this file.

Next you should commit changes to save them permanently to that branch. Normally before your first commit you would use git config that would contain your username or email to indicate who is making these changes.

ex: git config --global user.email EMAIL git config --global user.name “FULL NAME"

But in this case since it is all local and it appears that you will be the only one working on these files you can skip this step and make your first local commit:

git commit -m “First draft of project.txt file”

(-m is used to describe the changes you are making which will show up if you run git diff <filename>)

Now instead of using push/pull (which is primarily used for remote repositories) for a local git configuration you can simply use the git merge command.

You must first checkout the master branch before attempting to merge, because you cannot merge the master branch while in the clone repositories.

git checkout master
git merge dir_project1

I was able to find a way to push to a local branch if you'd rather do it this way:

git push . dir_project1:master
4
  • Hi and thaks. So, my idea was to create a main directory (base repo) myprojects where to insert all my projects that I created ("project1","project2", etc.), in order to have such a structure : myprojects: "project1", "project2", etc. So, from this structure so composed, I wanted to be able to do these 3 things: 1 create a project and run a git push without going to the server first and create an empty repo 2 clone a single project contained in the myprojects folder 3 clone, if necessary, the entire myprojects repo with all my projects contained within. Commented Dec 23, 2020 at 21:21
  • As far as I understand this thing (with git) is not possible, right? Thanks Commented Dec 23, 2020 at 21:21
  • @vincenzogianfelice Correct me if I'm wrong but when you say "without going to the server first" I assume you mean making changes locally before committing them to your git server? If this is the case then you do not need to even use pull/push commands to make changes locally. When you are ready to send changes to your git server that is when you would use push/pull commands. See How to Run Your Own Git Server Commented Dec 24, 2020 at 4:18
  • No, by "without going to the server first" I mean: "without going to the server first, create an empty repo, clone it on the local pc and finally do a git push to send the changes". In a nutshell, I mean if it is possible to upload a new project without first creating the "folder" on the target server. I do not know if you understood. Thanks and happy holidays Commented Dec 26, 2020 at 16:21

You must log in to answer this question.