Create a folder called git-demo
$ mkdir git-demo $ cd git-demo
Create a file called Hello.js and write some code. For git it does not matter, what’s inside the file. For the sake of having some code, we are creating this file.
function Greet(name) {
console.log(`Hello, ${name}`);
}
Greet('Arvind'); // prints: Hello, Arvind
Similarly, you can add more files and folders.
You have created folders and files and you want to start tracking the change versions. You need to inform git that I want to track all these files. You can do this by below command.
$ git init
With that, any changes done inside this file will be tracked by git.
Run below command to add all the changes to staging
$ git add .
You can also add selected file to staging by providing the file path.
$ git add <file_path>
You can commit changes using below command.
$ git commit -m "commit message"
The commit message is very important. Take time and write very descriptive commit message.
Generally development is done on local machine and changes are pushed to remote repository. You need to set the target respository localtion.
$ git remote add origin <https://remote/repo/path.git>
$ git push
This completes the basic cycle of using git.
But this is hardly enough when working in real projects. Specially, when multiple people are working on same repository but on different features. And that’s the sole reason why git exists,being multi-user. Like linux machines, multiple user can login to same machine and can work seamlessly.
As a matter of the fact, the inventor of Linux kernel and git version control system is the same person Linus Torvalds.
Coming back to multiple users working on same repository and on different features. How to overcome that?
Quick Links
Legal Stuff