If you are new to GitHub or working in a team using Git you probably will have to know your environment 😉
In this guide, we are going through some of the very basics of Git on VScode or any IDE 🙌
Git Workflow with package.json
1. Setting Up the Environment:
Before diving into Git commands, ensure you have Node.js and Git installed on your machine.
Running command: node –-version
(the result of that command should be a version of the node that we are currently having in our machine if not go ahead and install it from here)
2. Initial Setup:
Clone the repository to your local machine:
git clone <repository-url>
cd <repository-directory> / cd is used to move within directories or folders
3. Installing Dependencies:
Use npm to install all dependencies listed in the package.json file:
- npm install
This command will create a node_modules directory containing all dependencies required by the project.
4. Adding Changes:
After making changes to your project, stage them for commit using:
- git add .
Or
- git add “file”
This command stages all modified and new files for the next commit.
5. Committing Changes:
Commit your staged changes with a descriptive message:
- git commit -m “Your descriptive message here”
Ensure your commit message clearly describes the changes made in this commit.
6. Pushing Changes:
Push your committed changes to the remote repository’s main branch:
- git push
This command updates the remote repository with your local changes.
7. Working with Branches:
If you need to work on a new feature or bug fix, create a new branch:
- git checkout -b <new-branch-name>
Make your changes, stage them with git add, commit, and push as usual.
8. Updating from Main Branch:
Periodically, pull changes from the main branch to keep your local branch up to date:
- git pull origin main
This command fetches changes from the remote main branch and merges them into your local branch.
9. Checking Status:
To check the status of your local repository, including changes not yet staged for commit or changes in the remote repository:
- git status
This command provides information about the current state of your repository.
Commit your work as often as possible so others know what you are working on at the moment and we ensure working on the latest version of the project.