Git is a version control system that lets users track projects changes. Those projects (also called repositories) can be complicated, such as applications source codes, or just as simple as a bunch of text files.
In this blog, we will mimic working on a real-life project to learn how to interact with git. I've already created a repo that you can use to follow along with this tutorial.
The below are some terms you should be familiar with
That's enough for an introduction; let's start learning!
git clone
This command lets you clone/downlad the repo files locally.
git fetch
This command will fetch all the available branches in a repo.
git branch
This command will list all the available branches in the repo (run this after your do the fetch).
git checkout -b {branch-name}
This command creates a new branch for you; it creates a copy of the current branch before executing the command.
git add
This command will let you specify which files you want to
commit/push to your repo. If you want to push all your changes,
you can just do
git add .
git commit
This command creates a new commit containing the changes you
specified in the previous command (git add). One good practice
here is to always include a message with each commit.
git commit -m "my message goes here"
git push {upstream} {branch-name}
This command is the final step when making your changes; once you push, your changes will be available in the repo. By default, the upstream name is origin.
These are the most used commands and it will be super benificial for you to master them!
Let's now put them into action!
git clone https://github.com/MumenTayyem/github-basics.git
cd github-basics
git fetch
git branch
git checkout -b {change-this-to-your-name} # your branch name
will be your name
git add mumen.txt
git commit -m "your message goes here"
git push origin {your-name} # your branch name which you
specified in step#5
In this quick blog, you learned the basic commands to start using git. You then created your branch with your changes and pushed them to the upstream. Hope this was helpful for you!