Introduction :
Git and GitHub are powerful tools for version control and collaboration. They are essential for modern software development. Git and GitHub are indispensable tools for developers, providing version control, collaboration features and community support. They have revolutionized software development.
What is Git ?
Git is a version control system designed to handle everything from small to very large projects with speed and efficiency. It allows multiple developers to work on a project simultaneously without interfering with each other's work. It also helps developers track changes in their code and revert to previous versions when needed. It is used locally on a computer.
- Repository : A storage space where project files and their history are stored.
- Commit : A snapshot of repository at a specific point in time.
- Branch : A separate line of development. Branches allow you to work on different features or fixes without affecting the main codebase.
- Merge : Combining changes from one branch into another.
- Clone : Creating a copy of a repository from a remote server to local machine.
- Pull : Fetching and integrating changes from a remote repository to local repository.
- Push : Sending local changes to the remote repository.
What is GitHub ?
GitHub is a cloud-based platform for hosting Git repositories. It enables collaboration, code sharing, and open-source contributions. It provides a web-based interface and additional features such as :
- Collaboration Tools : Issues, pull requests, and project management tools for teamwork.
- Social Coding : You can follow other developers, star repositories, and watch projects to stay updated.
- Documentation : Markdown support for README files, wikis, and project pages.
- Pull Requests: Propose changes and review code.
- Issue Tracking: Manage bugs and feature requests
Workflow : Using Git with GitHub
Initial Setup :
- Git Installation :
First, click on this link to download git on the system : https://git-scm.com/downloads
- Pre-requisite :
Having an IDE like VS Code , if not download from here : https://code.visualstudio.com/
After the instalation run the below command on git bash to ensure that the installation is done successfully.
git --version
- GitHub Setup :
Login on GitHub and create a repository.
Git Configuration : git config
After creating an account on GitHub, use the same Username and Email adress in the bash to configure the Git. Actually, it a process of linking git with GitHub.We use git config command for this :
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
To check the configuration settings :
git config --list
Cloning of a Git Repository : git clone
To see a copy of a GitHub repository in our local system, we use the command git clone :
`git clone https://github.com/username/repository.git`
For example, in the code below:
Username : Prolayjit-B14
Repository Name : is C_Programming
git clone https://github.com/Prolayjit-B14/C_Programming
git clone “GitHub Repository URL”
Initializing a Git Repository : git init
After creating a repository on GitHub, use the git init command to initialize Git in local directory :
git init
Change Directory : cd
The cd command is used to navigate between directories in the command line.
cd folder-name
Example: This moves into the Documents folder.
cd Documents
Adding Files : git add .
The git add . command is used to add files to Git repository, use the this command. This stages changes, making them ready for commit :
git add <file-name>
For adding all files at a time :
git add .
Track Changes : git status
The git status command is used to tract the files in the repository in the local system :
git status
Commit Message : git commit
This git commit command records changes to the repository after adding files. It saves a snapshot of the current project state :
git commit -m "Commit message"
For an example, when the commit message is initial commit, the command would be :
git commit -m "Initial commit"
A Git commit message should be clear, concise, and descriptive.
Commit History : git log
The git log command shows the commit history of the current active repository :
git log
*Push Changes : `git push`*
The git push command pushes Changes from a Specific Branch to a Remote Repository :
git push <remote-name><branch-name>
For an example :
git push origin main
Here’s what each part means :
git push
→ Pushes changes to the remote repository.
origin
→ Refers to the remote repository (GitHub, etc.).
main
→ The branch name that is pushing to.
Download Changes : git fetch
This command downloads changes from a remote repository but does not merge them into your local branch :
git fetch origin
Switch Branch : git checkout
The git checkout command is used to switch branches, restore files, create new branches in Git :
git checkout branch-name
Combines Changes : git merge
The git merge command combines changes from one branch into another :
git merge branch-name
Pull Changes : git pull
Thi git pull command is used to download and merge the latest changes from the remote repository into local branch :
git pull <remote-name><branch-name>
For an example :
git pull origin main
Here’s what each part means :
git pull
→ Fetches and integrates changes from the remote repository.
origin
→ Specifies the remote repository (usually GitHub, GitLab, etc.).
main
→ The branch you want to update from the remote.
Delete Files : git rm
The git rm command is used to remove files from the Git repository and working directory :
git rm filename
Conclusion
Git and GitHub have revolutionized software development by enabling seamless collaboration, efficient version control, and secure code management. While Git provides the core version control functionalities, GitHub enhances it with cloud-based tools for teamwork and continuous integration. Together, they form an essential ecosystem for developers and open-source contributors.
GitHub Cheat Sheet
Here are few of my repositories :
- Event Management Website : https://github.com/Prolayjit-B14/Hackentine
- Project Showcase Website : https://github.com/Prolayjit-B14/Project-IoT
- Education Platform : https://github.com/Prolayjit-B14/Data-Daynamos
- Indian Classical Music : https://github.com/Prolayjit-B14/Bug-Fixes
If you like it, connect with me here :
Top comments (0)