Git & GitHub 101
January 23, 2023

Introduction to Git & Github
Git and GitHub 101: Before Starting, you need to understand that Git and GitHub are different.
Git is an open-source version control tool created in 2005 by developers working on the Linux operating system; GitHub is a company founded in 2008 that makes tools that integrate with Git.
You do not need GitHub to use it, but you cannot use GitHub without using Git. There are many other alternatives to GitHub, such as GitLab, BitBucket, and “host-your-own” solutions such as gogs and gittea. You do not need to use a remote to use it, but it will make sharing your code with others easier.
Now you understand this, let’s jump into the first Step


Step 0: Install Git and create a GitHub account
To install Git in MAC, the first Step is to install Homebrew, a popular package manager for macOS, and then, from your terminal, run brew install git.
Install Git on Windows is very straightforward; go to gitforwindows.org and Click on Download.
Once you installed Git and to make sure everything works fine, write the command “git version.”
If you have any problem with the installation, you can go to the Git documentation
To create your GitHub account, go to Github.com and then, go to sign-up
Step 1: Validate your credentials on your computer:
Now is time connect your computer with your GitHub account; you can do that by writing the command:
git config –global user.email “myuser@email.com”
git config –global user.name “username”
Step 2: Go to your GitHub account and create your first repository
In your Github Dashboard, click on Create new repository or New, then select the name of your repository and specify if it will be private or public.
Important: If you are using private tokens of external APIs that could be exposed, you need to select the Private option:
Step 3: Initializing the project
Option A: Now, you can go to your project and initialize your GitHub repository writing the command:
$ git init
And then connect it to your GitHub repository:
$ git add remote origin https://github.com/USERNAME/REPOSITORY.git
Use this option if you are starting a project from scratch.
Option B: The other option could be just copying the whole repository in your computer and create a new folder. In that case, you need to write the command:
$ git clone https://github.com/USERNAME/REPOSITORY.git
Use this option if you are working with an existing repository.
Step 4: Push your changes to GitHub
Once you start working on your local project and you want to upload your changes, there are three steps you need to follow
1. Add changes to the staging environment:
git add index.html (just add index.html)
git add *.html (just add the .html files)
git add . (All files)
git add -A (All files)
2. Create the commit
The commit will be the identifier or the change you are uploading:
git commit -m “Your message about the commit.”
3. Upload the changes:
If this is your first project, you work in the main branch. Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.
You always create a branch from an existing branch. Typically, you might create a new branch from the default branch of your repository.
You can then work on this new branch in isolation from other people’s changes to the repository.
And the branch you are working on is the origin, so the last Step to upload your changes is:
Git push origin main (Main is the name of your default branch, also works git push without the origin)
Step 4: Jumping between Branches:
If you want to create a new branch, you need to run the command: git branch new_branch
If you want to change your project to work in that new branch, you need to run the command git checkout new_branch
To see local branches, run this command: git branch.
To merge (locally), git checkout the branch you want to merge INTO. Then type git merge <branch> where <branch> is the branch you wish to combine FROM.
Step 5: Create a Pull Request.
If you want to get the updates, another developer did in a repository, just run the command:
git pull origin main (YOu have to change main for the name of the branch you are working)
Step 6: Conflicts:
To fix that problem, you have to go to the GitHub account, verify the file is generating the conflict, and copy the content of that file into your local file. Then you need to commit those changes and then try pulling again.
Now you have to merge. In this case, you will receive a message saying, “Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch”. You need to:
1. press “i”
2. write your merge message
3. press “esc”
4. write “:wq”
5. then press enter
Sometimes you need to merge two projects, but the system says the merge option needs to be fixed. In that case, you need to use git pull –rebase
Step 7: Other Commands
Git log: Git log is a utility tool to review and read the history of everything that happens to a repository.
Git help” If you are having trouble remembering commands or options for commands, you can use Git help
There is too much to learn about Git and GitHub in the documentation, but with this short guide, you can fully work with GitHub and consult the documentation if you are missing something.
Have Any Question?
If you want to add your backlink to my blog or need more information about my weekly coding training, please get in touch with me today.