Ari
Ari

Reputation: 6169

The basics of using Git locally

Disclosure, this is for an assignment.

The assignment asks for a local repository to be created on a HPC (high performance computer?), to clone an existing external repository to this machine, and to then allow local users to branch off from this local master repository. I've determined the following:

Create a folder on the HPC where the project will be stored:

mkdir path/to/project_folder

Inside of the project folder clone the existing repo:

git clone https://github.com/janesmith/projectXYZ.git

This will bring all the files from the github repo into the local folder. I now have a local version of the online repo but this is not necessarily a repo in itself.

Inside the local project folder again, I enter:

git init

This turns the folder in a bare repository. I then add the files:

git add *

This adds all the files. I then commit the files:

git commit -m 'first commit'

The assignment is very vague, I'm not sure how these users are accessing the same HPC, so what i'm assumming is and what I know is that they are local to the repo I just created. So does each user clone from the master repo?

git clone path/to/project_folder/projectXYZ.git user/projectXYZ

This would create a clone of the repo to a folder more local to the user.

But how does each of the users push changes back to the master repo?

Upvotes: 0

Views: 3010

Answers (1)

ElpieKay
ElpieKay

Reputation: 30868

If I understand your assignment correctly, the task is 1) to create a local repository, which serves as a blessed or central repository, and 2) allow users who log in on the same machine to clone this central repository, create their own local working repositories, push and pull between the central repository and their own repositories.

1.Create the central repository from github:

 git clone https://github.com/janesmith/projectXYZ.git --bare -- /path/to/local/repo

A central repository is a bare one in most cases. Make sure /path/to/local/repo is readable and writable for all users.

2.You, as the administrator, do some initialization work.

# create your own work repository
git clone /path/to/local/repo -- myrepo
cd myrepo
git checkout master
# edit files
git add .
git commit -m foo and bar
git push origin master

3.Notify other users that the central repo at /path/to/local/repo is ready and they can use it now.

4.User A logs in and creates his own repo.

git clone /path/to/local/repo -- userarepo
cd userarepo
git checkout master
# edit files
git add .
git commit
git push origin master
# oh, an error says push fails because of non-fast-forward
git pull origin -r master
# oh, merge conflicts encountered
# edit and solve the conflicts
git add .
git rebase --continue
git push origin master

5.User B wants a new branch feature_007 from master.

git clone /path/to/local/repo -- userbrepo
cd userbrepo
git checkout -b feature_007 origin/master
# edit files
git add .
git commit -m "feature_007 is good"
git push origin -u feature_007

6.User A is interested in feature_007.

cd userarepo
git fetch origin feature_007
git checkout feature_007
# edit files
git add .
git commit -m "fix a bug"
git push origin feature_007

Upvotes: 2

Related Questions