If you want to get into version control then one (popular) way to do this is to use Git. Let’s see how this can be set up simply.
First go to github.com and set up an account. For this post, we will use the username ‘myUser’ and the email address ‘email@example.com’. Change these values to whatever details you entered when setting up your GitHub account. We will also create a new repository called testrep.
Now we need to set up Git on our local machine. We are working on a linux box with Git installed, and will assume that you already have Git installed irrespective of the OS you use. Open the terminal and type the following:
git config --global user.name "myUser" git config --global user.email "firstname.lastname@example.org" git config --global credential.helper cache
These commands set up the user and email parameters for the user undertaking the version alterations and will be used to link to your GitHub account. The system is also set-up for caching.
Next we need to create a directory for the repositories to live in. We will also initialise git in that directory:
mkdir code cd code git init
Next we will create a file called README. Next open it in a text editor such as nano and add some text. Next up, we will add the file README to git:
touch README nano README git add README
The next thing to do is commit the file to the repository with a message:
git commit -m 'This is my first commit'
This all works locally. If you want to share the file, the next thing to do is to get it linked and uploaded to your GitHub account using the following commands:
git remote add origin https://github.com/myUser/testrep.git git push origin master
If you want to clone a repository that already exists online, then use the following command:
git clone https://github.com/ajggeoger/Spoon-Knife.git
If this repository is a fork, then it is possible to link to the parent upstream repository and update your files using these commands: git remote add upstream https://github.com/octocat/Spoon-Knife.git git fetch upstream
To find out information on the branch that you are on and what files need committing, then use:
To get your own files synched use:
git fetch origin
To find out what branches are available in your repository, you can type the first command below. The second command will show you the commit log for a stated branch showing you details on the author, date and message:
git branch -r git log origin/master
Leave a Reply