Hello developers, in this tutorial i am going to discuss about git. So in this git tutorial i will explain step by step why do you need git and github and how to set up git in your machine with SSH keys. I think this git tutorial is going to be the best git tutorial. Hope you will enjoy it. Let's start.
Git is becoming an ‘industry standard’. If you want to become a better developer, you may need to use Git to develop software and collaborate with other developers. Git lets you manage code development in a virtually endless variety of way. Here are benefits of using Version Control System/Git:
Note: if you don’t know how to run a command, please read the Recipe 1 - Introducing CLI (Command Line Interface).
Install Git on Mac
The easiest way is to install the Xcode Command Line Tools. You can do this by simply running this command.
xcode-select --install
Click Install to download Command Line Tools package. Alternatively, you can also find the OSX Git installer at this website:
http://git-scm.com/download/mac
Install Git on Windows
You can download GitHub for Windows to install Git:
https://windows.github.com
Install Git on Linux/Unix
You can install Git by running this command:
sudo yum install git
If you’re on a Debian-based distribution, use this:
sudo apt-get install git
When you first install Git, you should set your name, email address and enable coloring to pretty up command outputs. Open your CLI and run these commands:
1 git config --global user.name "Your Name"
2 git config --global user.email "Your Email Address"
3 git config --global color.ui auto
Note: Remember to replace Your Name and Your Email Address.
Now we have to set up our ssh keys. let's do it
~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
.
$ ssh-keygen -t rsa -C "your_email@example.com"
Note: (Don’t type the
$
; that just indicates that you’re doing this at the command line.)
Copy your public key (the contents of the newly-created id_rsa.pub
file) into your clipboard. On a Mac, in the terminal/shell, type:
$ pbcopy < ~/.ssh/id_rsa.pub
Paste your ssh public key into your github account settings.
$ ssh -T git@github.com
Hi username! You've successfully authenticated, but Github does not provide shell access.
Read also How to Recursively Remove .DS_Store Files on Mac OS
Git is very simple to use. First, you need to go to your working directory
cd Code/Laravel
Note: If you’re using Homestead, the Code directory is where we will put our Laravel apps. Code/Laravel is your working directory. You can use Git on Homestead or on your local machine, it’s up to you.
Now we can use the git init command to initialize Git:
git init
This command creates an empty Git repository. If you’re using Homestead, the path of the Git directory is:
/home/vagrant/Code/Laravel/.git/ . “.git” is a hidden folder and it doesn’t contain your project’s files yet.
Add and commit your files
Now we can use git status command to check the status of our working directory:
git status
You will see a list of untracked files, that means Git doesn’t monitor those files yet.
To tell Git that you want to include all these files, use the git add -A command:
git add -A
Note: Alternatively, you can use git add –a or git add –all or git add . command.
When we run the git status command again, you’ll see:
The git add command tells git to add changes in your project to the staging area. However, those changes aren’t saved yet until you run git commit:
git commit -m "First commit"
Note: You can use the -m flag (stands for message) to give a comment on the command line. My message is “First commit”, but you can use whatever you like. Well done! You’ve made your first commit!
Push your project to Github
Your new repository (repo) is empty. You need to upload your files to that Github repo. Every repository has a unique remote URL, your remote URL should look like this: https://github.com/YourGithubUsername/YourRepoName.git Take note of this link. Good! We will try to upload our Laravel app (/Code/Laravel) to Github.
git push
You now have your files on the cloud!
To download any repo, you can use the git clone command. First, navigate to the location where you want to place the cloned directory:
cd yourDirectory
Type git clone and the unique remote URL to clone the repo:
git clone https://github.com/YourGithubUsername/YourRepoName.git
This command creates a local clone of the repository on your computer.
Note: you can clone any public repository. If you don’t want anyone to download your repo, set it private.
Hope you've enjoyed this tutorial.
#setup-github #git #ssh-keys #configure-git #start-a-new-git-repository