Git and GitHub Documentation

Git and GitHub are commonly used to store files, code, folders, and project documents.

This documentation covers the major Git commands and their use cases.


1. Creating Repo

Repo is the short form of repository. It is basically a folder in Git/GitHub where you can store files, code, folders, and project documents.

Available Tutorials:

Tutorial for creating a repo using terminal

Tutorial for creating a repo using VS Code


Push First Code from Terminal

Setup Git

1. Create GitHub Account

https://github.com

2. Download and Install Git

https://git-scm.com/downloads

Initialize Your Git Account

1. Navigate/Open Git Bash

2. Connect your GitHub account

git config –global user.email “niloy@example.com“

git config –global user.name “username”


Create Repo from GitHub and Push Code/File/Folder Using Terminal

1. Go to GitHub’s website

https://github.com

2. Click on New Repo

Navigate to Your repositories and press the New option.

3. Create Repository

Give your repo a name, choose the privacy of the repo Public/Private, and press Create Repository.

4. Copy HTTPS Link

5. Open Git Bash/Terminal

6. Navigate to Your Project Folder

Navigate to the project folder or the folder you want to push.

7. Run the Commands

Run the commands written on the GitHub website after creating the repo, or create a new repository on the command line.

echo “# draft” >> README.md

git init

git add README.md

git commit -m “first commit”

git branch -M main

git remote add origin https://github.com/yourhttpsrepolink.git

git push -u origin main

Your code has successfully pushed if all the steps have been followed properly.


Push First Code from VS Code

Setup Git

1. Create GitHub Account

https://github.com

2. Download and Install Git

https://git-scm.com/downloads

Initialize Your Git Account

1. Navigate/Open Git Bash

2. Connect your GitHub account

git config user.email “niloy@example.com“

git config user.name “username”


Pushing Your Code/File/Folder

1. Open the Project Folder

Open the project folder from VS Code which you want to push, or create a new folder/project using VS Code. At least one file should exist.

2. Press

ctrl+shift+g

3. Publish to GitHub

Press Publish to GitHub and choose the privacy Private/Public.

4. Choose Privacy

Choose privacy by clicking Private or Public.

5. Select Files/Folders

Check if the files/folders you want to push are ticked and press Enter.


2. Clone

Cloning means downloading a repo from Git/GitHub.

Available Tutorials:

Tutorial for cloning repo using terminal

Tutorial for cloning repo using VS Code


Cloning a Repo from Terminal

1. Copy the Repo

Copy the repo you want to clone.

2. Open Git Bash/Terminal

3. Navigate to the Folder

Navigate to the folder on which you want to clone.

4. Run Git Clone Command

Run git clone command and paste the copied link from step 1.

git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY


3. Pull

Pulling basically means to pull the code on Git. This can be used in various factors such as updating the repo on your current device and filling up the missing codes/files/folders.

Use case:
If you code on multiple devices, you may need to clone your repo every time you start coding on a new device and delete the previous repo. Pulling updates your repo to the version you need, making the process easier.

Available Tutorial:

Tutorial for pulling repo using terminal


Pulling Into Existing Repo From Terminal

1. Open Git Bash/Terminal

2. Navigate to the Repo

Navigate to the repo saved on your device.

3. Initialize the Branch

git checkout main

Main is the default branch. You should choose the branch you want to use.

4. Fetch Latest Changes

Fetch the latest changes from the remote repository.

git fetch origin

5. Pull Latest Changes

Pull the latest changes from the branch.

git pull origin main

Note: This will not change/update repo(folder) name.


4. Commit Changes

Commit changes basically means to save the changes you did and update it on Git/GitHub.

Available Tutorials:

Tutorial for committing changes using terminal

Tutorial for committing changes using VS Code


Commit Changes and Push Into Repo Using Terminal

1. Open Git Bash/Terminal

2. Navigate to Your Repository

3. Stage All Changes

git add .

Or, stage a specific file:

git add filename.txt

4. Commit the Changes

git commit -m “Your commit message here”

5. Push Into Repo

git push


Commit Changes Using VS Code

1. Open the Project from VS Code

2. Press

ctrl+shift+g

3. Commit Changes

Type a commit message and press on commit. You can also choose the files you want to update by pressing the plus sign.

Note: You might not see any changes if you do not save the text files or update anything. Also, you cannot commit changes if the repo is not already created on Git/GitHub.