Table of contents
Git is presently one of the most popular distributed Version Control Systems (VCS) presently in the Tech world. Git is used for managing changes to code over time. It allows users to track and merge changes made by multiple developers on a project. whereas, GitHub is an online platform that offers hosting services for Git repositories. It also provides a web interface to manage Git repositories and other features like bug tracking, code review and various other collaboration tools. Understanding Git is an important part of the Agile Practices followed in the IT industry.
Git Basics
Git was created in 2005 by Linus Torvalds, the developer of the Linux operating system. It works by creating a repository that stores a complete history of all the changes made to a codebase over time.
I'll try to brief all the basic git commands in a nutshell format below so that beginners will be able to get started quickly.
- Initialize a new Git repository: This command will create a new Git repository in your current working directory.
$ git init
- Add changes to the staging area: This command will add changes from your working directory to the staging area for the next commit.
$ git add <filename>
#This will add the specific file to the staging area
$ git add .
#This will add all the files present in respective directory to staging area
- Commit changes to the repository: This command will create a new commit with the changes in the staging area, along with a commit message describing the changes.
$ git commit -m "commit message"
- View the status of your repository: To Verify if the files are currently present in the Staging area, use the below command to know the status. This command will show you the current state of files in your repository, including changes you have made.
$ git status
#This will show the files in staging area in Green color and files not in stage by Red color.
- Push changes to a remote repository: This command will push your local commits to a remote repository, such as GitHub.
$ git push <remote-repository url> <branch-name>
#E.g- git push origin main
#To verify the Origin url, run the below command
$ git remote -v
# main is the name of the branch here.
- Pull changes from a remote repository: This command will pull changes from a remote repository, such as GitHub, to your local repository. Pulling the changes will make your local repository in sync with the Remote repository changes performed by other members.
$ git pull <remote> <branch>
- Clone an existing repository: This command will make a copy of an existing Git repository from a remote source, such as GitHub.
$ git clone <repository-url>
GitHub Basics
GitHub is a web-based platform that was started in 2008 and is one of the largest, most popular platforms for hosting and collaborating on Git repositories.GitHub provides a central location for developers to host their Git repositories, Open source projects, allowing developers to contribute to projects they are interested in, submit bug reports, suggest new features etc.
Let's see a brief overview of GitHub features below.
Pull Requests: Pull Requests (PRs) enable developers to propose changes to code hosted on a Github repository, allowing other team members to review the changes and approve them before merging them into the main branch.
Branching: Branching is an important feature of Git and Github. A branch is like a copy of the codebase that you can modify independently of the main branch. This feature allows teams to work on their own particular feature or fixes, without worrying about impacting the main codebase.
Merging: Merging is the process of combining two or more branches into a single branch. It's essential when you have multiple developers working on the same codebase in a parallel manner.
Let's see the commands for this branching & Merging feature below.
# Create a new branch for the feature $ git checkout -b <branch-name> # Perform changes & commits to this branch # Switch back to main branch $ git checkout main # Merge the new feature branch into main $ git merge <branch-name>
Forking: Forking allows developers to create their own copy of a repository on Github, with all existing files and folders. This is useful when you want to work on a project, but don't have neccessary permissions to directly contribute to the repository. Forking creates a whole new copy of the repository, independent of the original, so you can make changes to the code without affecting the original repository.
Conclusion
Git and Github provide developers with a powerful set of tools to manage their code changes and collaborate effectively with others. Knowing how to use these tools effectively can help streamline development workflows and improve code quality in your Programming career.
I hope i was able to provide quick outlook into the basics of Git and Github and my best wishes to all coding geeks out there in their endevours !!!