An easy way to Git - Beginner's Guide

Learn Version Control using git.

Git - A Version Control Software

Git is a distributed version control software that basically allows multiple people to work in parallel and it saves a history of all changes made.

Version control ???? What does that means

Well It is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.

image.png

Step 1 Let's Begin Setup a Git Account

Just go to Github and sign up a free account for you.

Step 2 Installation of git on your machine

Download GIT as per your machine OS from here.

Step 3: Create a Local Git Repository

After installing or updating Git, the next step is to create a local Git repository.

  1. Open Terminal/Bash/Command prompt on windows
cd ~/Desktop
mkdir myproject
cd myproject/

In this example, we changed the directory to Desktop and created a subdirectory called myproject.

  1. Create a Git repository in the selected folder by running the git init command. The syntax is:
git init [repository-name]

image.png Now you have successfully created a local Git repository.

#Step 4: Create a New Repository on GitHub GitHub allows you to keep track of your code when you're working with a team and need to modify the project's code collaboratively.

Follow these steps to create a new repository on GitHub:

1. Log in and browse to the GitHub home page.

Find the New repository option under the + sign next to your profile picture, in the top right corner.

image.png

2. Enter a name for your repository, provide a brief description, and choose a privacy setting.

image.png

3. Click the Create repository button.

GitHub allows you to add an existing repo you have created locally. To push a local repository from your machine to GitHub, use the following syntax:

git remote add origin https://github.com/[your-username]/[repository-name.git]
git push -u origin master

image.png

Step 4: Add a File to the Repository

Git notices when you add or modify files in the folder containing the Git repository but doesn't track the file unless instructed. Git saves the changes only for the files it tracks, so you need to let Git know you want to track changes for a specific file.

You can check which files Git is tracking by running:

git status

image.png Git notifies you if you have any untracked files. If you want Git to start tracking a file, run the following command:

git add [filename]

image.png

In this example, we instructed Git to start tracking changes for the test.txt file. Rerunning the git status command shows that Git is tracking the specified file.

Cheatsheet for GITHUB

git cheat.jpg