Git

Git installation process

The first step is to install Git on your WSL.

Enter the following command in your terminal:

sudo apt install git

Git Workflow Guide

1. Preparation (Local Work)

These steps are done on your local machine before interacting with the remote repository.

Command

Purpose

git status

Check the current state of your working directory and staging area.

git add .

Stage all changes in the current directory, preparing them for a commit.

git commit -m "Your message"

Permanently save the staged changes into your local repository history.

2. Synchronization (Pulling Remote Changes)

These commands are used to bring new changes from the shared remote repository to your local branch.

Command

Purpose

git fetch

Downloads new data and commits from the remote repository but does not modify your local files or branches.

git pull

Downloads remote changes (fetch) AND immediately integrates them into your current local branch (merge). This is the command that most often triggers a conflict.

3. Handling Conflicts (If git pull Fails)

If git pull results in a merge conflict, the following steps are required:

Command

Purpose

git status

Shows which files are currently in an ‘unmerged’ (conflicted) state.

Manual Edit

Open the conflicted file(s), remove the Git markers (<<<<<<<, =======, >>>>>>>), and choose the final correct code.

git add <conflicted_file>

Stages the manually corrected file, signaling to Git that you have finished resolving that specific conflict.

git commit

Completes the merge process by creating the final merge commit. Git usually pre-fills the message for you.

4. Sharing (Pushing Your Changes)

Once your work is committed and you have ensured your branch is up-to-date with the remote (via a successful pull or merge resolution), you send your changes to the remote.

Command

Purpose

git push origin <branch_name>

Uploads all your local commits to the specified remote branch (e.g., main).

git push

Shortcut command if the upstream branch has already been set (common after the first push or after a clone).