Git-ing Started: An intro to Git
Lets talk about Git. This is the first post in a series of using git. In this post, Im going to explain these things:
- What is Git?
- Why you should be using it
- How to use it
If you'd rather watch a video than read though, you can do that right here also!
What is it Git?
Git is Distributed version control meaning it keeps track of changes made to files and there is a remote server somewhere else in the world that also has those changes. A common remote server is GitHub, which I will talk about in the next video, so make sure to hit that subscribe button and the bell to be notified when I post it.
Basically, its like track changes in Word but for files in a repository, or folder, that are stored locally and can be pushed to a remote server if needed. These files can be any type, but it works best with text files.
Its usually used by developers to track all the changes made in source code and to collaborate on projects since it supports working on different parts of the project and merge them together. Since each computer also gets the full history of the repository, or project, the developers can also go back to another point in time and adjust things there.
Those advantages also stand for being a solo dev, so lets talk about why you should use it.
Why you should use it?
If youre not on a team, I still say you should be using git and here are my reasons.
- Allows you to see what changes are made
- Allows you to easily roll back changes if needed
- Allows you to have a backup of your developer environment if using a remote server like GitHub
How does one use git?
Weve talked about why and what is git, but how do you actually use git? Like what software do you need and what do you do?
First off, download and install git
from git-scm.com
Thats the only extra piece of software you need, since git can be ran through the command line
Workflow
- Initialize git to the repository or project folder, Ill call it repo from here on out
- Create and or modify folders and files
- Add those files and folders to gits staging area
- Commit the changes to git
- Push those changes if you have a remote server
All 5 of these steps have commands, so let's work through creating a basic website that has git.
Example:
Creating a folder for the project
Create a new folder, Im going to be creating it in my ptd
folder, but it could really be anywhere on your computer.
Initialize git
Now, we are going to tell git to start tracking this folder.
- Open the terminal app or whatever you use to access the command line
- Change your working directory to the folder you just created
- Use
cd
followed by the path to the directory to change your working directory cd developer/git-website
- Use
- in the terminal, type
git init
. Now git is working on this repo
Create an index.html file
Now, lets create a simple index.html file that just shows GIT IS THE BEST and make sure to save it in the git-website folder
Stage the file
Since, the file has been created, we need to actually tell git to track this file and the current state of the file. To do this, we use the command git add {file path}
. This will need to happen for any change you want git to store.
git add index.html
adds index.html to the staging area.
You can repeat this step for as many files as you need.
Record the changes
Now, to actually tell git to record the changes that were added by committing those files. When committing files, you must specify a message.
git commit -m Adding the index file
Push those changes
Again, this step would only happen if a remote was setup, which we didnt do in this video, but will do in the next one! So make sure to hit that subscribe button and the bell so you dont mix it.
The command to push the changes is git push
Youll repeat the git add
, git commit
, and git push
a lot throughout the project so get used to those commands.
Thats the basics of what git is, why you should use it, and how to actually use it.
In the next post, Ill talk about adding a remote server tool so that you can push your changes to a remote repo.
If you found the post useful, then please share with anyone you think will find this useful.
Original Link: https://dev.to/maeganwilson_/git-ing-started-an-intro-to-git-4hmb
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To