First you need to install Git. Download + install it on your PC from HERE: https://git-scm.com/
Then, create an EMPTY repository on GitHub - without readme, ignore and licence files. Let's name it travel-site. For this example I will be using my real GitHub repository: https://github.com/AleikovStudio/travel-site
Now you will be working with the terminal - you can use Window's cmd or the PHPStorm's terminal. I prefer to use the terminal built inside the PHPStorm - it is: better, faster and more intuitive.
From your GitHub copy the repository URL - for example https://github.com/AleikovStudio/travel-site.git (note the .git extension at the end); Instead of AleikovStudio (my username in GitHub - use yours).
Inside your PHPStorm project's folder you will need to initialize Git (btw you can drag the folder with your project into the terminal). In the terminal type:
Now, let Git know where to upload your project files online (your push repository). To do so, in the terminal type:
git remote set-url origin https://github.com/AleikovStudio/travel-site.git
git remote add origin https://github.com/AleikovStudio/travel-site.git
To check which is your push repository on GitHub, type:
git remote -v
Very common and frequently used git command is:
It will check for changes and will give you recommendations.
To add all changes to the stage, type:
git add .
The . here stands for all files. To add a particular file (for example: index.html) you can type:
git add index.html
Also you can stage your changes with (here -A is for ALL):
git add -A
To commit new commit + add a message (for example: "Added new message"), type:
git commit -m "Added new message"
You can also stage + commit in one command line:
git commit -am "Stage and commit in one command"
To push the files (from your local PC) for the first time to your GitHub repository online, type:
git push origin master
To push the changes afterwards, simply type:
To create new branch, type:
git branch footer
This will create new branch named footer
To see which branch you are currently using, type:
To change (checkout) the branch:
git checkout testimonials
* instead of the testimonials (name of the branch) you can type master (the main branch):
git checkout master
To create and at the same time checkout a new branch (in this case named header), type:
git checkout -b header
To merge the branch (for example: testimonials branch) with the master branch (the main one), type:
git merge testimonials
Please note: you need to be ON master branch to merge other branches (you can check on which branch you are currently on by typing git branch).
* instead of a testimonials you can type the name of the branch you wish to merge with the master one
Here are some other useful Git commands (and some for the terminal):
CLEAR TERMINAL (COMMAND PROMPT):
STOP A TASK ON THE TERMINAL (COMMAND PROMPT):
CLONE A GIT PROJECT FROM GITHUB:
git clone https://github.com/LearnWebCode/welcome-to-git.git
CHECK GIT VERSION:
CREATE NEW DIRECTORY/FOLDER (for example: hello-world):
CHANGE DIRECTORY TO (for example: hello-world):
CREATE FILE (for example: index.html):
If you are getting an error you might need to install touch npm package. In the terminal type:
npm install touch
To learn more about npm packages and how to use them with PHPStorm, please click here.
RESTORE A FILE FROM A COMMIT:
git checkout -- .
FILE STAGED (READY TO BE COMMITED - from red color to green):
git add -A