Create new Bare Repository
These steps will create a new bare repository called learningGit in ~/code/learnGit/bareRepo/.
- Create the containing directory
- Go to the correct directory
- Create a new bare repository
- Move into the new repository
- Look at the contents of the bare repository
mkdir -p ~/code/learnGit/bareRepo/
cd ~/code/learnGit/bareRepo/
git init --bare --shared learningGit
cd learningGit
ls
|
|
Create Working Repositories
For this example, we are going to create 2 working repositories.
This is so you can see how changes don't affect the other repositories unless pushes & pulls are done.
Create a Working Repository
These steps will create a new working repository called learningGit in ~/code/learnGit/ that is a clone of ~/code/learnGit/bareRepo/learningGit.
- Move to the appropriate directory
- Clone the initial repository
- Move into the working directory
- Look at the contents (Note: learningGit has not yet had any files added to it)
cd ~/code/learnGit
git clone ~/code/learnGit/bareRepo/learningGit
cd learningGit
ls -a
|
|
Create a Second Working Repository
These steps will create a second working repository called learningGit2 in ~/code/learnGit/ that is a clone of ~/code/learnGit/bareRepo/learningGit.
- Move to the appropriate directory
- Clone the initial repository
- Move into the working directory
- Look at the contents (Note: learningGit has not yet had any files added to it)
cd ~/code/learnGit
git clone ~/code/learnGit/bareRepo/learningGit learningGit2
cd learningGit2
ls -a
|
|
Add the First Set of Files to the Repository
There are multiple steps for adding the files:
- Creating a repository with a working directory
- Creating the files
- Staging the files
- Committing the files
- Pushing the files to the bare repository.
Create a Working Repository
These steps will create a new working repository called learningGit in ~/code/learnGit/ that is a clone of ~/code/learnGit/bareRepo/.
- Move to the appropriate directory
- Clone the initial repository
- Move into the working directory
- Look at the contents (Note: in this example, learningGit has not yet had any files added to it)
cd ~/code/learnGit
git clone ~/code/learnGit/bareRepo/learningGit
cd learningGit
ls -a
|
|
Create the New Files
These steps create README.txt and README1.txt in ~/code/learnGit/.
- Create README.txt
- Create README1.txt
- Look at the git status to see 2 untracked files.
echo This repo is for Learning Git. > README.txt
echo Another file in the repository > README1.txt
git status
Note: the files are not yet stored in the repository.
|
|
Stage the files
This step stages the addition of README.txt and README1.txt
- Stage the files
- Look at the git status to see 2 staged files.
git add .
git status
Note: the files are staged, but not yet stored in the repository.
|
|
Commit the Files
This step stores README.txt and README1.txt in the local repository.
- Commit the files
- Look at the git status to see no uncommitted changes.
git commit -m "Add the first files"
git status
Note: the files are stored in the local repository, but are not yet in the bare repository.
|
|
Push the files to the bare repository
This step pushes the files to the bare repository.
- Push the files without specifying the remote or branch (fails)
- Push the files specifying the remote and the branch (succeeds)
git push
git push origin master
|
|
Clone Pre Existing Repository