What is Git?
Git is a free and open-source distributed code management and Version control system that is distributed under the GNU General Public License version. In addition to software version control, Git is used for other applications including configuration management and content management.
Are Git & GitHub are same?
Absolutely not, a lot of people think that both are the same maybe just because of similarities in their name but actually Git is a version control system that lets you manage and keep track of your source code history. GitHub is a cloud-based hosting service that lets you manage Git repositories. If you have open-source projects that use Git, then GitHub is designed to help you better manage your repositories perfectly as same as a book library.
>> Download Git in your system : Tap here!
>> Join GitHub : Join here!
Cheat Sheet for Git
Initialising git
Initialising a git repository starts with the
git init
command.
Also, If you want to check the status of files and if there are any changes, then thegit status
command is used.Adding and commiting
Now, for adding things to the staging area git add
command is used. The staging area is files that are going to be part of the next commit. For committing we use:
git commit-m "[your message]"
Create a Branch
When you create a branch in your project, if you want to make some changes but you are not sure about them it can fail. The command is:
git branch [branch name]
For switching to that branch, use:
git checkout [branch name]
Add commits
When you start making changes in your files when you are on your branch.
You can add stuff to your staging area and commit it. It won't affect the main or master branch (commands are same as above ↑)
Open a Pull Request (PR)
Pull Requests initiate discussion about your commits. Anyone can see exactly what changes would be merged if the pull request is accepted.
In very simple and casual words, the pull request is basically taking permission from the project owner to make certain changes or commits that you want to be made in the same project and when your pull request is merged with the main branch, all the changes that you've been made will reflect over there too!
Pull requests in (GitHub) are basically used for reviewing and discussions.
Deploy
After getting your pull request reviewed you can deploy it to verify them in production. If it causes an issue, you can deploy it back to the original main branch.
Merge
After verifying in production, you can merge your branch into the main branch.
Other popular useful commands:
git command add origin [link of repository]
↪ You need this before you push your commit to GitHub. Especially when doing it for empty git repo.
git push
↪ It is used when you want to push your commits to the GitHub repo from your computer.
git clone [link of your repository]
↪ Clone/copy a repository on your local computer to work with.
git log --graph
↪ It will help you show your history of commits in form of a graph.
git diff
↪ It will help you show the difference by comparing your working area with staging.
That's all from my side in this blog! all the important "Git" commands are covered in this blog, hope you'll like this also this will be helpful to you!
Download the GitHub Cheat sheet from: "here"! (tap to redirect there)
Reach me out in the comments below or in my socials : LinkdIn / Twitter to let me know what you think of it. Stay tuned for some more interesting blogs coming up soon.
Also, If you like my content and want to support my efforts please like👍🏻, share🔃 & subscribe to the newsletter 📩 to be get notified whenever I post a new blog.
Happy Coding ! Have a nice day :)