All the basics you need to start working with Git
Make your data more reliable using Git. See TOC for your use-case.
So, What's Git?
On an abstract level, Git is a tool that helps to manage your projects (basically files and folders) by tracking the changes made and providing some additional features (reset, revert, merge, clone, etc).
A repository is just a folder that is managed by git.
Do not delete the project folder, before the commit operation.
Case 1: You have your project locally
Suppose you have your project folder named local-project on your system, and you want Git to manage it. Follow these steps to do the same.
Step 1: Go to the project folder and type git init
. This will create a folder (hidden), that has all the required data to manage your project.
Step 2: Type git status
to know the current status of the repository. We can see that the files are untracked by Git.
Step 3: Type git add .
This takes the repository to the staging area, which is kind of an intermediate state before Git stores it permanently.
Step 4: Type git commit -m "added local project"
to commit to the repository. Commit means taking a snapshot of the current state and storing it permanently.
Step 5: Let's delete a file, to check if Git is managing the project.
Step 6: Type git restore local-file.txt
We can see that the file is restored.
The next steps are for deploying your project in a distributed cloud-based platform viz GitHub. GitHub uses Git under the hood and enables storing, tracking and collaborating of projects on the internet.
Step 7: Create a repository on GitHub: https://github.com/new Give the Repo name as local-project (not mandatory). After clicking on the "Create Repository Button", copy the URL as shown below.
Step 8: In the terminal, type git remote add origin
https://github.com/harsha-commit/local-project.git
and git remote -v
to check if the URL is added.
Step 9: Check the branch using git status
. Type git push origin master
to push the local repo to GitHub.
Step 10: Go to the URL and check if the repository is created on GitHub.
Step 11: Go celebrate ๐ฅณ๐. Your project is on GitHub. Now do not stop learning Git and GitHub, it has many other features to explore. Enjoy, Love, Learn and Explore โญ
Case 2: You have the project on GitHub
Step 1: Copy the URL from the required repository.
Step 2: In the terminal, type git clone
https://github.com/harsha-commit/github-project.git
and in the folder created, see the contents. Git uses .git folder and clones the project in our local system.
Step 3: Now you can create new files, edit or delete the existing files in the local repository. Type git status
to check the current state of the repo.
Step 4: Type git add .
Then type git commit -m "added new file"
to commit to the repository. Commit means taking a snapshot of the current state and storing it.
Step 5: Type git status
to know the current branch of the project. Type git push add origin main
to push your changes to GitHub.
Step 6: Check the repo in GitHub.
Step 7: Go celebrate ๐ฅณ๐. Your project is on GitHub. Now do not stop learning Git and GitHub, it has many other features to explore. Enjoy, Love, Learn and Explore โญ