Mastering Open Source through Git
Dive into Git commands to effectively contribute to the Open-Source.
Table of contents
Introducing Git
Hello Reader! Today we'll dive into and get introduced to the world of Open-Source through Git and GitHub.
So basically, Git is an Open-Source version control system developed by Linus Torvalds and currently being developed collectively by developers around the world.
Let's take a scenario where you are working on a large codebase along with other developers and you have to change some part of the code, then you will have to share entire code with them through any messaging platform every time you make any change. Or if by chance, you have written some buggy code which in future may cause the problem to the application, then it may be difficult for you to track that after which fix, something went wrong.
To tackle this git was developed to track any changes in the codebase by anyone, so that it becomes easier for us to find the problematic code there and take action. Similarly in case of sharing the code every time after fix, remote repository concept was introduced where any developer can get access and make the changes there itself before sharing every time to everyone.
Then GitHub was developed which gave the platform to use Git system and collaborate with other developers. To use GitHub, there are mainly 2 methods to manage repository and code:
Graphical User Interface
Command Line through Git Bash
We will mainly focus on using GitHub through Command Line (Terminal) as it is complicated at first but later becomes easy and cool to work on as compared to GUI after much practicing. Trust me, literally.
Commands
pwd | It is used to print the present working directory (Folder). |
cd <directory name> | It is used to change the directory. |
mkdir <file name> | It is used to create a new directory. |
touch <file name> | It is used to create a new file. |
git init | It is used to initialize a new git repository. |
git status | It is used to check the status of the git repository. |
git add . | It is used to add all the files to the staging area. (Means making them ready to get uploaded into the remote repository). |
git remote add origin <remote repo link> | It is used to connect the local repo with remote repo and make it origin. |
git branch -M main | It is used to change the branch from master to main. |
git commit -m “message” | It is used to commit our staging by writing the reason for staging in the commit message. |
git push -u origin main | It is used to push all the files after committing to the remote repo. |
git log | It is used to get all the commit histories. |
git restore –staged <file name> | It is used to remove the file from the staging area. |
git rm -rf <file name> | It is used to forcefully delete the file. |
git reset <hash id of commit> | It is used to revert back to that stage. |
git stash | It is used to send the files backstage without committing for deleting in future. |
git stash pop | It is used to call the files from backstage. |
git stash clear | It is used to delete from backstage. |
git branch <branch name> | It is used to create a new branch. |
git checkout <branch name> | It is used to start committing to that branch. |
git merge <branch name> | It is used to merge the branch into the main branch. |
git commit -am “That was easy!” OR git config –global alias .ac “commit -am” then git ac “noice!” | It is used to skip add before commit. |
git commit –amend -m “nice!” | It is used to change the message of the last commit. |
git add . then git commit –amend –no-edit | It is used to add files to the last commit. |
git revert better -days | It is used to undo a commit with a new commit. |
git log –graph –oneline –decorate | It is used to make git log easier to read. |
git blame <file name> | It is used to see all the history of commits. |
git clone <repo link> | It is used to clone the remote (online) repository to your local system. |
--> Ignore "<>" across the file name command.
Conclusion
In conclusion, mastering Git commands is like using a powerful tool that empowers you to explore the beautiful landscape of version control with precision. With each command learned and mastered, you'll unlock the ability to streamline your workflow, collaborate seamlessly with other developers, and safeguard your project's integrity.
As you progress on your Git journey, remember that proficiency comes with practice and patience. Accept the challenges, learn from your mistakes, and live in the satisfaction of overcoming obstacles.
As you bid farewell to this article, remember that the true meaning of mastering Git lies not only in the commands you execute but also in the understanding and appreciation of the collaborative ecosystem on GitHub. The Open-Source universe awaits ahead and make it your own. Bye-Bye and see you next time.