Super Quick Git Tutorial
Basic Usage Example For Working With Git
If you want to collaborate with a few other developers, you will either need to have a Git server running or be using a Git hosting service. In the example below we will be using GitHub as it’s one of the most popular available to use and is free if you don’t mind your repositories being public.
In the example below you will need to have Git installed on your laptop or PC to then connect and work with your GitHub repository.
GitHub Accounts
Most of the work below will be using the command line, but we first need to move to the GitHub website to create an account(If you don’t have one already) and create a repository.
- Start by creating an account on GitHub. Go to the following URL and create your own account: https://github.com/, if you don’t have one already.
- Take a little time to set up your account and add all your specific details and passwords.
- Make sure that you also set up SSH keys on GitHub as this will allow you to pull and push changes to and from the GitHub servers.
Create Your Repository
We are going to create and start working with a new repository called testrepo, so you should still be logged onto GitHub and run through the following:
- While you are logged into GitHub, in the top right hand corner of the screen, click on the + and select “New Repository”
- You will be presented with the screen above to give your repository the name testrepo and description and display it as Public or Private. When you are happy, click on Create Repository. We have somewhere to store our repository, but we still need to initialize our repository. This is where we will move to our laptop or PC and start working on the command line.
- Go to your development environment and create a directory that you want to be developing on.
- We will create a basic README.md file, so run the following command to create the README.md file and populate it with its first line:
echo “# GitAppDev” >> README.md - Then initialize your repository by running the following Git command:
git init - To see if there have been any changes made in your repository, run the status command where we should only see the README.md file that has been added:
git status
On branch master
Initial commit
Untracked files:
(use “git add <file>…” to include in what will be committed)
README.md
nothing added to commit but untracked files present (use “git add” to track) - As our output states we need to add our untracked file if we want to track it, so we then use the add command to allow Git to track our new file:
git add . - When we are happy with all our additions, then we can commit the changes have added:
git commit –m “Our first commit” - All this is still on our local Git application, on our laptop of PC, so let GitHub know we are going to add some more information. Get the URL for the repository you have created and run the following command(remember to substitute your GitHub username with the <username> below):
git remote add origin git@github.com:<username>/testrepo.git - Finally, push your changes back to the remote repository on GitHub:
git push –u origin master
If you access the GitHub web interface again, you will be able to see the new files added to your repository.
Found this post useful? Kindly tap the ❤ button below! :)
About The Author