Git or the Global Information Tracker is an open source software which is free and an important tool in the software development lifecycle. More often than not, projects involve many developers working simultaneously on an insane number of files and a version control system is needed.
Version control is also important to locate and fix bugs. While the straightforward method involves creating multiple copies of the same file and labeling them appropriately, this approach has a problem. Apart from a large number of near-identical files, there has to be a system of granting permission to read-write-execute to a number of developers without compromising the source code. The next step in the version control system was the arrival of distributed version control.
This distributed version control system contains the entire codebase (a collection of source code used to build the system or application) including the entire history with changes and updates made along the way which is accessible to everyone working on the project.
A distributed version control system comes with several benefits like:
- Automatic management branching and merging
- Speedy operations
- Ability to work offline
- No dependency on a single location for backups
And Git is the world’s most popular distributed version control system using peer to peer version control as opposed to centralized system.
What is Git?
Git was created by Linus Torvalds in 2005 for the development of the Linux kernel. Git used its Git directory to turn every computer into a full fledged repository with complete history and version tracking ability.
While it may be described as the “stupid content tracker” or the “information manager from hell” but that sure didn’t deter the rising popularity of Git amongst software developers with almost 93.9% of them using it as their primary source control system.
Advantages of Git
- Non-linear development – Git allows rapid branching and merging with specific tools to visualize and navigate non -linear changes. The branches are light-weight and are a reference to one commit. Teaching the parental commit can construct the full branch.
- The distributed development allows each developer to have a full development history with changes in each repository copied to another and imported as development branches that can be merged just like a locally developed branch.
- Compatible with existing systems and protocols
- Efficient handling of large projects making it fast and scalable
- The authentication of code history by storing history in such a way that a particular version or “committ” depends upon the complete development history leading up to that commit. Once published,any changes made to the old versions are highlighted.
- A toolkit based design which makes it easy to chain components together
- Multiple algorithms for completing merge
- Automatic garbage (unwanted loose objects) collection from the repository
- Git stores newly created objects using packs which help store a large number of objects delta-compressed as one packfile
What is the difference between Git and GitHub?
Let’s see the difference between git and GitHub now. 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. There are other options to GitHub like GitLab and BitBucket. We hope you have some rough idea about the similarities and difference between git and GitHub
Let’s now take a look at the basic steps to start using Git.
- The first step is really a no-brainer. Install Git and create an account with a username that will help identify you 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
- use a text editor using the command `touch newfile.txt`and save the “newfile.txt.
- Use the git status command check if Git identifies the file
- If you make changes to the file, the Git notices but is not going to do anything about it
- The changes need to be made through “commit”, which is make changes to the file and ask Git to add it to the commit
- But the files that need to be “commit” cannot be done without “staging environment”
- Once the files that need to be added to “commit” are identified, use the command git add <filename> command to add them to the “staging environment”
- After all the files are added to the staging environment, use the command , git commit to ask Git to package them into a “commit”
- Running a Git status will now show the file added to the staging environment
- The file is 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 keeps 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 use the command Run git checkout -b <my branch name> to create a new branch and GIt will move you to this off branch from the primary branch
- Using the command git branch will confirm that the branch was created
- Creating a new GitHub repository
- To work with a team GitHub can be used to collaborate and work on project code
- Create a new repo on GitHub , name it and provide a brief description
- 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
- Running the command “git push origin yourbranchname” GitHUb will automatically create the branch for the remote repository
- 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 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 branch and the most recent changes made at GitHub can be tracked at the local computer
- The git log command will now display the updated status
- Git checkout master command can switch branches back to the primary branch
Well congratulations, you have successfully learnt the difference between git and GitHub now.
Git is beneficial both for beginner developers and professionals at most advanced levels because of several benefits it offers, like security, flexibility and scalability. With vast community sources, books, tutorials, podcasts, the learning is easier and enriching. Know more about difference between git and GitHub from FunctionUp today
FunctionUp is a coding bootcamp that focuses on backend engineering skills and trains students through our NSDC approved curriculum over a period of four months.