Collaborate Quickly With git

In the following article I am going to illustrate how you can share a git project with your team within your local area network.
Note: I am using Ubuntu OS throughout this article.
First thing first :
you have to decide your workflow first, it can be in 2 ways:
1 dedicate a machine
2 share from your personal computer
Anyway whatever you decide this can be achieve by using ssh authentication or using git demon.
In this section we are focusing on sharing using ssh key authentication…….
Lets understand this by following scenario:
lets assume Bob,Alice and Mike is a part of a small team and working on modules of same project.
now its necessary to make sure they can work on same code without interrupting someone else’s workflow
so, they decided to use git for version control:
What is Git ?
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Now instead of going with available services like github or bitbucket they have decided to use git locally over LAN
now they have chosen a regular computer with regular office machine i am going to call this a git server in further story…….
Now Bob, Alice and Mike generate ssh keys by hitting the command into terminal `ssh-keygen
` this will generate new key value pair for your computer, backup your keys if already exists or it will be overrides……
science our employees doing it first time they will get the following results:
hp@hp-HP-15-Notebook-PC ~ $ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/hp/.ssh/id_rsa): /home/hp/.ssh2/id_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/hp/.ssh2/id_rsa. Your public key has been saved in /home/hp/.ssh2/id_rsa.pub. The key fingerprint is: SHA256:Wajzk72KRL/rwNGvGx2JL+sgmtsTxQlh+cmU8N94230 hp@hp-HP-15-Notebook-PC The key's randomart image is: +---[RSA 2048]----+ | ++ . | | .o.o . | | *.o. . | | B+ * . | | .= S = | | .o = B + . | | ..= B * . . E| | +.o + B . . | | +....oX+. | +----[SHA256]-----+
i have changed the save path ,one can keep this default. to keep default press the enter key
/home/bob/.ssh2 ├── id_rsa └── id_rsa.pub
Next step :
copy id_rsa.pub file for each employee to git server
Tip:
copy directly from your computer to any other computer using scp
by hitting following command :
scp filename user@ipaddress:/path/to/copy
for example the command for copy id_rsa.pub from employees computer to git server as follows:
Bob: [copying and renaming file to desktop to avoid further confusion] cp ~/.ssh/id_rsa.pub /home/hp/Desktop/bob_id_rsa.pub scp /home/bob/Desktop/bob_id_rsa.pub gitserver@192.168.1.110:/home/gitserver/Desktop/ [using scp command copying bob_id_rsa.pub to git servers desktop directory] Alice and Mike follows the same! NOTE: first time it might ask for add remote host to known_hosts, type yes and press enter then it will ask password for remote computer in our case password for gitserver
now from gitserver
perform cat Desktop/bob_id_rsa.pub >> ~/.ssh/authorized_keys
and for rest of people.
reason of adding public keys of all users to authorized_keys
to avoid entering password each time while doing ssh to remote server and further git processes like cloning the repository.
That’s it!!
now our employees can able to clone project repository from our local git server machine………..
Now from gitserver computer :
create a directory at any location of choice : let's say within desktop mkdir mywebsite cd mywebsite
now within our newwebsite
directory run a command git init
it will : Create an empty Git repository or reinitialise an existing one
now either you can perform this command within existing project or within our newly created directory.
after initialising mywebsite as git create any file like README.md
then stage the changes by performing git add .
it will add your changes to staging area, after that perform git commit -m “initial commit”
when -m stands for commit message.
now if you hit git branch -a
it will show all branches available. results wil be simmilar to * master
which is our default branch:
you can modify your terminal to display current working branch just past the following code end of ~/.bashrc file [ubuntu : may need to edit with sudo for take changes to effect, then perform source ~/.bashrc to save modifications]
parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
now we are done at server side for now…….
now our employees can clone this repository by hitting git clone
command will look like following in our case git clone gitserver@ip-address:/path/to/project
for example Alice can clone our project mywebsite by running following command within her terminal git clone gitserver@192.168.1.110:/home/gitserver/Desktop/mywebsite
now Alice can found a directory named mywebsite within the location she has performed git clone, now she can perform all her tasks by creating a separate branch for her module of work.
Now remember the option you have decided!
If we have dedicated server for git then you should initialise git with git init — bare
but if work need to be done on gitserver as well then one may also face fetal error while checking out master branch because its already checked on git server.
Tip:
if you are also need to work on server you should make temporary branch and keep it checked out on server to avoid master already checked out error.