Let's learn about git! This article is dedicated to beginners and
complete crash course on git and GitHub to get you started with your first git project. I will provide some link at the end of this article, so you can deep dive even more.
if you prefer video over article check this out
- Git is free and open source distributed version control system.
- Git was created by Linus Torvalds, he also created Linux Kernel.
- Git is designed to handle everything from small to very large projects with speed and efficiency.
- Git is easy to learn and has a tiny footprint with lightning fast performance.
Version control software keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.
Software developers working in teams are continually writing new source code and changing existing source code. The code for a project, app or software component is typically organized in a folder structure or "file tree". One developer on the team may be working on a new feature while another developer fixes an unrelated bug by changing code, each developer may make their changes in several parts of the file tree and at the end it all gets merged to a single source which can be deployed.
so, let's say you have a project that is deployed. Now, if you want to make any changes to that project for an instance adding an AUTH feature you would probably make a copy of the final version and then make any modification to that copy. That will serve two purposes: 1. you can test your code beforehand, and 2. you have now a history record of your initial codebase and the newer code base.
This above process might just work for you if you are the only developer working on the project and you make modification to your code every now and then.
However, if you have hundred's of developers working on the codebase and every one making thousands of changes every day, you can clearly imagine the above process will be a mess. Git solves this issue.
on a side note: why every software has a three number name, like: macOS Big Sur version- 11.0.1?
Semantic Versioning 2.0.0 ⬅ check this out.
Install Git on Mac OS X: There are several ways to install Git on a Mac. In fact, if you've installed XCode (or it's Command Line Tools), Git may already be installed. To find out, open a terminal and enter git --version.
$ git --version git version 2.7.0 (Apple Git-66)
Apple actually maintain and ship their own fork of Git, but it tends to lag behind mainstream Git by several major versions. You may want to install a newer version of Git using one of the methods below:
The easiest way to install Git on a Mac is with Homebrew:
Open your terminal and install Git using Homebrew:
$ brew install git
Verify the installation was successful by typing which git --
$ git --version git version 2.9.2
Configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
$ git config --global user.name "Emma Paris"
$ git config --global user.email "email@example.com"
- Download the latest Git for Windows installer.
When you've successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. The default options are pretty sensible for most users.
Open a Command Prompt (or Git Bash if during installation you elected not to use Git from the Windows Command Prompt).
Run the following commands to configure your Git username and email using the following commands, replacing Emma's name with your own. These details will be associated with any commits that you create:
$ git config --global user.name "Emma Paris" $ git config --global user.email "firstname.lastname@example.org"
We will be working with GitHub. If you don't have an account, go ahead and open an account in GitHub. Alternatively if you prefer to use other services like bitbucket or GitLab, feel free to do so, for the most part they all works the same way.
On the next page, name your repo and choose the appropriate options. Optionally I always keep the add a README file unchecked because I usually add my own README.md file with the first commit and also it does give you the second screen shot where you can get some useful git commands.
as you can see the above instructions gives you a step by step commands to run in your terminal to get started.
- git init will create a folder in your project directory and it will be hidden because you would never have to open that file.
- next command to run in the terminal is git status.
- next command to run is git add <filename> or git add .
git add .
This . will stage all the files and you will be using this
method for the most part. If you want to just track one specific
file, simply change the . with the filename like
git add app.js
this command will change the color of the files to green meaning
these has been staged. You can check that by running git status
notice on step 3 git actually showing you which command to run
- Next command to run git commit.
git commit -m 'first commit'
- By default git has the branch named as master. However we are going to change the name of the branch to main.
git branch -M main
- It's time to link our remote GitHub link to our git project with the bellow command.
git remote add origin https://github.com/w3tsa/git-crash-course-2021.git
- finally we are ready to push our code to the repo.
git push -u origin main
_There are two more commands I want to show you is
git clone <repo link> which will clone down a repo from your GitHub to your local machine. The second one is
git checkout -b branch-name which will create a separate branch for you to work on instead of main branch.
checkout the video bellow.
- Git - https://git-scm.com/
- How to install Git - https://www.atlassian.com/git/tutorials/install-git
- Semantic Versioning 2.0.0 - https://semver.org/