Git Tutorial - bounswe/bounswe2024group11 GitHub Wiki

Introduction

Git is a version control system that allows users to work on a project simultaneously. It keeps track of the changes to the files, enables users to return to any version of the code and enables users to work collaboratively.

You can access the documentation on merging and resolving conflicts

Installation

To install Git, visit Git Website and follow the instructions for your workspace.

Configuration

Configure your Git username and email address so that the Git can associate your commits with your username. git config --global user.name "Your Name" git config --global user.email "[email protected]"

Initializion of a Repository

Navigate to your project directory and initialize a Git repository using the command git init. This command creates a folder named .git

Git Workflow

Cheking Status

Use git status to see untracked files, changes not staged for commit and changes to be committed.

Adding Files

Use git add <file> to add the files to the staging area.

Committing Changes

Use git commit -m "your commit message" to commit the staged changes to the Git repository.

Branches

Creating a Branch

Use git branch <branch_name> to create a new branch in the repository. The changes in this branch will not affect the other branches.

Changing the Current Branch

Use git checkout <branch_name> to switch to a different branch. You can combine creating and switching to a new branch by using git checkout -b <branch name>

Merging Branches

First, switch to the target branch. git checkout <target_branch>. Second, merge it with the source branch.git merge <source_branch>. If the target branch is an ancestory of the source branch, the merge is done by the fast-forward method. If not, it is done by the recursive method.

Managing Remote Repositories

Cloning a Repository

You can clone a remote repository to your local using git clone <url> command.

Push Changes

You can make changes to the repository in the local and push them to the remote repository using git push <remote_name> <branch_name>

Pull Changes

You can fetch changes from the remote repository and merge them using git pull <remote_name> <branch_name>

Fetch Changes

You can fetch changes in all branches without merging them with your repository, you can use git fetch <remote_name>. If you want to fetch only a specified branch, you can use git fetch <remote_name> <branch_name>

Helpful Links

⚠️ **GitHub.com Fallback** ⚠️