Introduction
When working on a project, you may make many changes to your files. It can become difficult to keep track of what you changed. Git helps you solve this by allowing you to record your changes and keep a history of your work. GitHub provides a place where the project can be stored online.
What is Git?
Git is a tool used to keep track of changes made to files in a project. It helps you have different versions of your work so that you can see how your project has changed over time. This can be useful when working on a project because you can keep track of your progress and go back to an earlier version if needed.
What is GitHub?
GitHub is the online platform where you can store and share that Git project.
What is a Repository?
A (repo) is a place where your project is stored and git keeps track of it’s history.
Creating a Local Folder
The first step is to create a folder on my computer where I will keep my project in my files.
This is called a local folder because it is stored in my computer.
For example, I can create a folder called my-first-project. I can then open Git Bash and move into the folderusing the cd command.
mkdir my-first-project
cd my-first-project
The **mkdir** command is used to create a new folder, while the **cd** command is used to move into that folder.
So local folder - is basically my project's home on my computer.
You create folder first, then git comes later when you
Enter fullscreen mode Exit fullscreen mode
bash
git init
so the order is
- Create folder
- Enter folder
- Git init
- Git starts tracking the project
Staging with git add
Staging is the process of preparing changes before a commit.
After creating or changing a file, I need to tell git which changes I want to include in my next commit.
This is done by using the git add command.
Example, I can use
git add .
The . means that Git should stage all the changes in the current folder.
Also can stage one specific file by using its name:
Bash
git add README.md
After using git add, the changes are placed in the staging area and are ready to be committed.
**Committing with git commit**
After staging my changes, the next step is to commit them.
A **commit** is like a saving version or checkpoint of my project. It allows Git to keep a record of the changes I have made.
To create commit, I use the following command
Enter fullscreen mode Exit fullscreen mode
bash
git commit -m “Initial commit”
the -m allows me to add a message describing what I have committed. The message should briefly explain what the changes are
For example
Bash
git commit -m “Add README file”
What is SSH
SSH stands for Secure Shell.
It is a secure way of connecting my computer to git hub. In Git, SSH can be used to connect my local repository to a GitHub repository.
It uses SSH keys to verify the connection between my computer and GitHub.
Once the connection is set up you can use commands such as
Bash
git push
to send your GitHub securely.
Connecting the project to GitHub
After creating a repository on GitHub, I need to connect it to the project on my computer. This allows Git to know where my project should be sent when i want to upload my work.
I can connect my local repository to GitHub by using the git remote add command. Example:
bash
git remote add origin [email protected]:ninadavid4/my-first-project.git
Here, **origin** is the name given to the GitHub repository. The SSH address after origin tells git where the remote repository is located.
I can check if the connection has been added by using
Bash
git remote -v
This shows the GitHub repository connected to my local project.
Then later, when you use:
Bash
git push
Git knows where to send your commits.
##Conclusion
In this project, I learned how to take a project from a local folder on my computer and connect it GitHub using Git and SSH. I learned how to create a Git repository, stage changes using `git add`, save them using `git commit`, and connect the project to a remote GitHub repository. I also learned that SSH provides a secure way for my computer to communicate with GitHub.
Enter fullscreen mode Exit fullscreen mode