Git

Git is a widely used version control system for tracking code changes in software development.
Developed by Linus Torvalds, it offers powerful features for collaboration, code management, and project history.

With Git, developers can work locally, experiment, and easily revert changes. It allows precise control over code evolution and smooth collaboration through merging, conflict resolution, and branch management. Git's distributed nature enables offline work and minimizes reliance on a central server.

Its branching model promotes structured workflows and concurrent development. It provides a rich set of tools and commands for version control operations, and it has a thriving community and integrations with popular hosting platforms.

Whether for personal or team projects, Git is an essential tool for efficient and collaborative software development.

How To Use

When writing new code, create a branch with the new feature, and when finishing the feature merge it into original (often master) branch and then delete the feature branch.

Here are some tips to help you effectively use Git:

Bash Commands

Here are useful git bash commands.

Clone Repository

git clone <url>

See information about current branch

git status

Create Branch

git branch <new_branch>

Create branch and switch to it
git checkout -b <new_branch>

This is shorthand for:
git branch <new_branch>
git checkout <new_branch>

Change Branch

git checkout <branch>

Show Branches

git show-branch

See Difference

git diff
use arrow up/down to scroll, and press q to quit.

see difference in file:
git diff <file>

Compare branches:
git diff <branch1> <branch2>

Pull & Push

git pull
git push
or git push <repository> <branch>

Add A File To Staged Files

git add <file>

add all files to staged files in current directory:
git add .

Unstage file:
git restore --staged <file>

Unstage all files
restore --staged

Discard Changes In File

git checkout -- <file>

Discard all changes in all files
git checkout -- .

Remove File From Staging Area

git reset HEAD -- <file>

Remove directory from staging area
git reset HEAD -- <directoryName>

Commit With Message

git commit -m "changed some things"

Stop Detecting Changes In File

git update-index --assume-unchanged <path>

See History Of Commits

git log

Revert Commit

If you wish to undo/revert the last commit you can do the following, using the commit hash that you get from the git log command:
git revert <commit hash>

Remove Last Commits

To remove the last commit from git, you can simply run git reset --hard HEAD^.
If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits.
You can increase the number to remove even more commits.
Then, force a push (git push --force origin or git push --force origin master should be enough).

List Settings

git config --list will list the settings. There you should also find the email of the user.

Merge

run git checkout master to change the active branch back to master.
run git pull.
run  git merge <new-branch> to merge the new feature into the master branch.

Note that git merge merges the specified branch into the currently active branch. So we need to be on the branch that we are merging into.
Run git push.

If there are conflicts, solve them.

Rebase

git checkout feature-branch
git rebase master

Cherry Pick

Powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD.

git cherry-pick <commit-hash>

Delete Branch

Delete locally :
The -d option stands for --delete, which would delete the local branch, only if you have already pushed and merged it with your remote branches.
The -D option stands for --delete --force, which deletes the branch regardless of its push and merge status, so be careful using this one!

"git branch -d branch_name"
"git branch -D branch_name"

Delete remote:
"git push <remote_name> --delete <branch_name>".

Change Last Commit Message

git commit --amend -m "New commit message"

Folder Structure

A good folder structure is very important for locating and accessing files easier.
Then the developers can work faster.

The Root

The root should be reserved for configuration files, documentation (such as .gitignore and others).
Also, it can contain VS solution files, git files and ".env.example" file to show the used environment variables (so the developer can set them in his computer locally).

/src

This is where all source files are placed.
However, in languages that use headers (or if you have a framework for your application) don't put those files in here.

/lib, /dep, /inc

This is the directory where all your libraries/dependencies/ files to include should be stored.
Also, if you have your project in multiple files, put your headers and attached source in here.

/doc

Documentation goes in here.
For example, "docs.md" file.

/res

A less common one.
For all static resources in your project.
For example, images and audio.

/tools

Convenience directory for your use.
Should contain scripts to automate tasks in the project, for example, build scripts, rename scripts.
Usually contains ".sh", ".bat" files for example.

/build

The place where your built files will go.
Usually split into two directories, Debug and Release, it can contain binaries, .DLLs and any compiled files.
It may also contain build scripts, like makefiles, but they should generally be in the root.

/test

Contains all tests.
tools and build will have prod and test directories.
root/test will have directories - test_name that will have lib, src, res directories.

/modules

Store modules (unless the framework use it elsewhere).

README Template

MD files (Markdown documentation) are used to lightweight markup language.
Common syntax is:

  • Headings:

    # Heading 1
    ## Heading 2
    ### Heading 3
    ...
  • Emphasis:

    *Italic* or _Italic_
    **Bold** or __Bold__
  • Unordered lists:

    - Item 1
    - Item 2
     - Subitem 2.1
     - Subitem 2.2
  • Ordered lists:

    1. Item 1
    2. Item 2
    3. Item 3
  • Links:

    [Link Text](https://www.example.com)
  • Images:

    ![Alt Text](image-url.jpg)
  • Inline code:

    `code`
  • Code blocks:

    ```python
    code
    ```
  • Blockquotes:

    > This is a blockquote.
  • Horizontal rule:

    ---
  • Tables:

    | Column 1 | Column 2 |
    | -------- | -------- |
    | Value 1  | Value 2  |
  • Escaping characters:

    \* Escape special characters \*

You can create a file called file_structure.md and store it in doc folder and explain about the folder structure.

Here is template for "README.md" file:

Project Title

One paragraph of project description goes here.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them.
```give examples``` (Store this in special code frame).

Installing

A step by step series of examples that tell you how to get a development env running

Say what the step will be:
```give examples``` (Store this in special code frame).
And repeat
```until finished``` (Store this in special code frame).

End with an example of getting some data out of the system or using it for a little demo.

Running The Tests

Explain how to run the automated tests for this system.

Type Of Tests

Explain what these tests test and why

Documentation Templates

Here is example for "file_structure.md" file:

Folder Structure

Information about the folder structure of the project.

/build

Binary build files created from makefiles.

/doc

Documentation files about the project.

/lib

Libraries used in source code.

/obj

Object files created when compiling source code files using makefiles.

/res

Resources used by source code.

/src

Source code of the prod version of the project.

/test

Test source code used to test the project.

/tools

Tools used to run the project.

Tools

If you prefer using Git with a GUI (graphical user interface) over command-line operations, you can use these tools:

Up Next

Effective task management is crucial for organizing your work, staying productive, and meeting project deadlines. In the next step, we delve into various task management techniques and tools that help you plan, track, and prioritize your tasks effectively.`