Unlocking the Power of Git & GitHub | 10 Easy Steps To Start Using Git & GitHub
Differences between Git and GitHub :
While the name can be misleading but Git and GitHub are not the same, GitHub is a company making tools that integrate with Git. One may not need GitHub to work on Git but GitHub cannot function without the use of Git.
GIT (Global Information Tracker) is open-source software. It's free and a very important tool in software development. Many developers work on a project which consists of an insane number of files.
The distributed version control system of granting permission to read-write-execute to many developers without compromising the source code.
GitHub = Git + Hub (Like-minded People)
GitHub is an extremely popular Git repository hosting service where millions of software developers come together to store, manage and contribute to their own and others’ code. GitHub facilitates the interaction of like-minded developers, who can view, or even access, each other’s work and discuss errors, and of course, potential solutions.
Here are several benefits of Git :
Automatic management branching and merging
Speedy operations
Ability to work offline
No dependency on a single location for backups
Let’s now take a look at the basic steps to start using Git.
The first step is to Install Git and create an account with a username on the platform and track your work
Create the local Git repository
Open the terminal and decide where the project will be placed on the local machine using the change directory command
To initialize the Git repository, run the git init command.
Adding a new file to the repo
- Create a new file using your text editor and save it in the local repository.
Staging
If you make changes to the file, Git notices it but is not going to do anything about it.
The changes need to be made through “commit”, which is making changes to the file and asking Git to add it to the commit.
Commit
The changes made to the file are yet to be added to the "commit".
The next step of “commit” can be completed using the command git commit -m "Your message about the commit" which should be a clear explanation regarding the changes made so that other developers can have the context.
Creating a new branch
If a new feature needs to be added but you don’t want to disturb the main project that’s when git branches come in.
Git branches keep track of the commit the new branch came from, keeps a track of the history and can also merge the changes to the primary branch
You can create a new branch and Git will move you to this off-branch from the primary main branch.
Creating a new GitHub repository
To work with a team GitHub can be used to collaborate, Create a new repo on GitHub, name it and provide a brief description about it.
GitHub asks whether this repo will be built from scratch or be added to the repo already created locally, one can make a choice accordingly.
Push the branch to GitHub
- The commit to the branch can now be pushed to the GitHub repo allowing other people to see the changes made and once approved by the repository owner the changes can be merged to the primary branch.
Pull request
A pull request alerts the repository owner that someone wants to make changes to their code allowing them time to review the code
The Merge Pull Request allows merging the changes with the primary main branch.
Getting the GitHub changes back to your computer
The GitHub changes made to the branch like commit and merge are not reflected on the primary branch on the local machine yet.
The “git pull origin master command” can be used while working on the primary main branch and the most recent changes made at GitHub can be tracked on the local computer.
The git log command will now display the updated status. The Git checkout master command can switch branches back to the primary main branch.
Congrats, you've successfully mastered Git.
In conclusion, Git is beneficial both for beginner developers and professionals at the most advanced levels because of the several benefits it offers. Git is very crucial for any developer who's looking to upskill himself. With vast community sources, books, tutorials, and podcasts, learning is easier and more enriching.