Git is an open-source version control system that works locally to help developers work together on software projects that matter. Linus Torvalds, the developer of the Linux kernel, created Git in 2005 to help control the Linux kernel's development.
Today we are gonna discuss the common but most important Git commands for any developer.
Some common Q&As
What is a version control system?
A version control system is a system that helps you keep track of changes you've made to files in your project. Using this system we can revert to the previous version of our project if something went wrong or we want to do so.
What are the types of version control system?
- Distributed Version Control System
- Centralized Version Control System
Are Git and GitHub are same?
No, Git is a version control system that helps us keep track of changes in the files among our various projects whereas GitHub is a cloud platform on which we can manage our code and project repositories which are powered by Git or we can say that we manage Git repositories on GitHub.
Now we have a basic idea about Git. So we can look up its commands now!
Git requires some configurations when it gets set up on a system. Basic configurations include username and email. Whenever a user commits some changes in a project then it makes a record of changes and saves the reference of the user.
Check your Git configuration
By running this command you can check the user's Git configuration for that particular computer system
git config -l
Configure your Git Username
You can configure your username from the command given below
git config --global user.name "thelovekesh"
Configure your Git User Email
Set up your email using this command which will be used in the commits later:)
git config --global user.email "[email protected]"
Initializing a Git Repo
Starting up Git within a project and getting it connected.
git init
git clone https://www.github.com/username/repo-name
git remote or git remote -v
git remote add upstream https://www.github.com/username/repo-name
Staging in a Git Repo
Creating files staged after modifying a file and marking it ready to go in the next commit.
git status
git add . git or add my_script.js
git reset my_script.js
Committing in a Git Repo
Recording changes made to the repo.
git commit -m "Commit message"
git commit -am "Commit message"
git commit --amend -m "An updated commit message"
Branching in a Git Repo
git branch
git branch new-branch
git checkout another-branch
git checkout -b new-branch
git branch -d branch-name
Collaborating and Sharing in a Git Repo
Downloading changes from another repository or sharing changes with the larger codebase.
git push origin main
Some repos use master instead of main in their commands
git pull
git merge upstream/main
Showing Changes in a Git Repo
See changes between commits, branches, and more.
git diff --staged
git diff a-branch..b-branch
git diff 61ce3e6..e221d9c
Sources
Something Missing?
If something is missing in this post or if you found some part confusing, then you can:
- Create a New Topic on Ask Codebulbs
- File an issue on the GitHub
- Open a new discussion on GitHub
- Make a tweet at the @thelovekesh
We love hearing from you!
Give Feedback
Share your experience as a reaction!
Thank you for the feedback! (Join Codebulbs Writers Club)
Sorry to hear that. Please tell us how we can improve. (Suggest an Improvement)