First, we need to install Git: the version control software.
Open a terminal on your Windows or Mac and then write the following commands:
cd project_name
git init
4.1.1. Create a file named index.html containing a simple <h1> tag 4.1.2. Git does not know about the file index.html. We can check the tracked files using the following command:
git status
4.1.3. The git status command allows you to know the status of the project: If it is initiated, modified, staged
4.1.4. For Git to recognize this file, we need to add it to the staging area and create a commit.
There are multiple ways to add files to the staging area.
git add filename
git add filename1 filename2
git add .
4.1.5. To remove a file from the staging area, we need to use the following command:
git rm --cached filename
A commit allows us to create a snapshot of the project state at that point of time. To create a commit, we use the following command with -m stands for message and we list the message associated with this commit.
git commit -m 'your message'
The message should be short and accurately describes the changes made. A clear message would allow us to identify a specific commit and eventually roll back to that state if needed.
To list all commits in The Local Repository
git log
To list only latest 3 commits
git log -p -2
To go back to a specific commi
git checkout commitID
Commit types
| Commit Type | Title | Description | Emoji |
| ———– | ———————— | ———————————————————————————————————– |:——:|
| feat
| Features | A new feature | ✨ |
| fix
| Bug Fixes | A bug Fix | 🐛 |
| docs
| Documentation | Documentation only changes | 📚 |
| style
| Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) | 💎 |
| refactor
| Code Refactoring | A code change that neither fixes a bug nor adds a feature | 📦 |
| perf
| Performance Improvements | A code change that improves performance | 🚀 |
| test
| Tests | Adding missing tests or correcting existing tests | 🚨 |
| build
| Builds | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) | 🛠 |
| ci
| Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) | ⚙️ |
| chore
| Chores | Other changes that don’t modify src or test files | ♻️ |
| revert
| Reverts | Reverts a previous commit
First, we need to create an account GitHub.
git remote add origin https://github.com/user/repo.git
For the first push, we need to use this commend:
git push --set-upstream origin master
OR
git push -u origin master
git pull
git clone URL_OF_REPO
The branch is the copy of the main(or master) at branching instant. After branching, the branch and the master don’t see each other. You can create as many branches as you want.
git branch branch_name
git checkout branch_name
git checkout -b branch_name
git merge branch_name
git branch
To rename any existing branch
git branch -m <old-name> <new-name>
To rename the current branch
git branch -m <new-name>
The branch must be fully merged in its upstream branch.
git branch -d branch_name
OR Use the flag -D to force the branch delete.
git branch -D branch_name