Thankfully, the process of cloning a remote Git repository is actually rather simple once you know what you are doing. Forking a repo is just as easy. Again, once you know what you are doing. Below I am going to walk you through the steps in a very simple and easy to understand way.
Cloning a Remote Repository
First lets change to a directory that we want to use as a landing zone when we download — or more accurately — clone a remote repo.
#cd /root && mkdir git
Now using the remote git URL, lets clone the fatmin github master repo @ https://github.com/Fatmin/general.git. Note that the destination of general.git name of our remote repo.
#git clone https://github.com/Fatmin/general.git
This creates the directory “general” which contains all the downloaded files, scripts, and code that we have previously checked in to our github repo. This command also initializes our pwd as a Git repo… no need to run Git init.
Forking a Remote Repository
Now lets say that we want to make a fork of the fatmin master repo. For example, lets say that we are working on a new puppet module and want to be able to test it out and then push to a new branch that we have decided to call testing.
First we need to create a new local branch. We accomplish this with the command below. As stated above, our branch is called testing.
#git checkout -b testing
Now lets grab our puppet module, script, file, code, what have you, and move it into our pwd of /root/git.
Note that even though our file is now located inside our cloned and branched repo, we need to tell Git to add it to the repo with the command below. This command will add any new files or directories in our newly created local repository.
#git add .
Now we need to commit the changes in our local repo. Here we are adding a comment along with our commit. Then we are pushing our changes back up to the remote origin (https://github.com/Fatmin/general.git) into a new branch called testing.
#git commit -m “pushing scripts to testing branch” && git push origin testing
Once we are happy with our changes, or whatever, we can then log into github and approve the merge between our master branch and our testing branch.