Git Basics

Configuring Git

Set your username and email address, which will be associated with your Git commits.

     git config --global "Your Name"
     git config --global ""

Initializing a Repository

Create a new Git repository or initialize an existing directory as a Git repository.

     git init

Adding Files

Add files to the staging area before committing them.

     git add filename

Committing Changes

Commit the changes in the staging area to the repository.

     git commit -m "Your commit message"

Working with Branches

Creating Branches

Create a new branch to work on a feature or bug fix.

     git branch branch_name

Switching Branches

Switch to a different branch.

     git checkout branch_name

Merging Branches:

Merge changes from one branch into another.

     git merge branch_name

Checking Repository Status

View the status of your repository, showing changes and untracked files.

     git status

Remote Repositories

Cloning a Repository:

Clone a remote repository to your local machine.

      git clone remote_repository_url

Pushing Changes:

Push your local changes to a remote repository.

      git push origin branch_name

Pulling Changes:

Fetch and merge changes from a remote repository.

      git pull origin branch_name

Adding Remote:

Add a remote repository to your local repository.

      git remote add origin remote_repository_url

Handling Conflicts

Resolving Conflicts:

When merging branches, conflicts may arise. Resolve them manually and commit the changes.

      git mergetool  # Opens a visual merge tool
      git commit -m "Merge conflict resolution"

Viewing Commit History:

View the commit history of your repository.

      git log

We use cookies to personalize and enhance your experience on our site. By using our site, you agree to our use of cookies.
  More information about cookies