Project collaboration using Git
In earlier post, we discussed that why we switched from SVN to Git for Classpro source code revision control. The very next concern for us was where to store the initial git repository. We had the option of going for a git hosting service such as Github or create our own git server. We decided to create our own git server on remote server.
Install Git on both Server and Client machines.
if you’re on a Debian-based distribution like Ubuntu, try apt-get to install Git:
Prferred way of doing GIT on server:
In order to initially set up any Git server, you have to export an existing repository into a new bare repository — a repository that doesn’t contain a working directory.
This is generally straightforward to do.
In order to clone your repository to create a new bare repository, you run the clone command with the —bare option. By convention, bare repository directories end in .git, like so:
git clone --bare my_project.git
output: Initialized empty Git repository in /var/www/my_project.git/
warning: this creates an empty git repository.
Step 1 on client machine clone the remote repository using,
git clone [email protected]:/var/www/my_app.git
output: Initialized empty Git repository in /var/www/my_app/.git/
warning: You appear to have cloned an empty repository.
Step 2 create a Readme file inside the my_app folder and add it to the stage and commit it,
git add Readme git status git commit -m "Initial commit adding readme file"
Step 3 check the remote repository information using
Step 4 check your branches in local repository
git branch output: * master
Step 5 lets create a new branch that reflect new code in the project.
git checkout -b develop master
output: Switched to a new branch 'develop'
Step 6 again, check your branches in local repository
git branch output: * develop master
Step 7 lets switch to master branch
git checkout master
output: Switched to branch 'master'
Step 8 adding remote path to git
Step 9 pushing local master code to remote repository
Step 9 same way push the develop code to remote repository
Step 10 to fetch the latest code from the remote repository
git fetch origin < branch name >
Git Tips: To remove a file(s) from Git
git rm --cached < file path >