Assuming this is the code we have:
When we start changing things regularly, it's hard to keep track of all of the details or get back to the previous files.
So, when the project becomes big and lots of contributors come in, we have to use source control management tool like git.
Using Git
Firstly, we initialize the total files and create a git repo.
Then we choose which files to track and which not to track.
Now, once you make any changes into any of the files. For example(main.py), it will track that down.
Now assume that you have multiple files and you want just one files changes to be confirmed and create a commit, you need to take that specific file to the staging area and then you can commit.
Note: Before commit, you have to take that file to the staging area.
Installing git and using it
First we install it ( here we used centos as our operating system)
Then you go to the folder where you are working and want to track. Then use this init command to initialize git.
Now we have no changes here to track , so we will see this.
We can track our desired files using the git add
command
Now, assume that you have added some new codes and tried to check if git has been able to track that or not using git status.
Now we have taken it to the staging area.
Now we have committed our files.
Here all of the files which was kept for tracking has been added.
Remote repository
As your team increases, more and more people codes and you guys need to work centrally now.
So, you now need to keep an online central repository from where you will download (fetch/pull) codes or push (upload) codes.
Using remote repositories
now you want to track all of the files under your folder "my application" and then use the github remote repository for that.
Here you first locally add them all and take it to the staging area and then create your first commit.
You then go to GitHub and create a repository there.
In the beginning this repository will be empty and you will now upload (push) your commit to this remote repository.
Thus all the files will move to the remote repository too.
Now add this commit to your remote repository.
Now push this commit to the remote repo.
Here we have pushed to the master (which is main now) branch.
Now, when someone wants to get all of your codes, they first need to download it (clone it)
the user can then modify the codes and contribute too. Then there will he come to know about Pull requests (PR), Merge conflicts and many other terms.
But that's not for this blog.
Top comments (1)
Thanks for the informative post 😊