Skip to content

DhanukaNaveen/git-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 

Repository files navigation

Git Tutorial with GitKraken

A customized guide to everyday Git commands and GitKraken.


Table of Contents


Prerequisites

Before we begin, ensure you have the following installed on your system:


1. Setting Up Git and GitKraken

To begin using Git in your development environment, first download and install Git. Follow these steps:

Go to the Git Downloads page and select the appropriate version for your system (Windows, Mac, or Linux).

After installation, verify Git is installed by opening a terminal and typing:

git --version

Next, install GitKraken, a graphical interface for Git that makes managing repositories much easier. Download from GitKraken Official.


2. Creating and Initializing a Git Repository

Create a new project folder or open your existing project in VS Code.

Open your terminal and navigate to your project folder. Type:

git init

This will initialize an empty Git repository in your project folder.


3. Staging and Committing Changes

After initializing your repository, add files to Git:

Create or edit a file (e.g., index.html) in your project.

Stage the file to Git by typing:

git add index.html

Or stage all files:

git add .

Commit your changes:

git commit -m "Add index.html file"

Committing Changes


4. Using GitKraken to Enhance Your Workflow

GitKraken helps visualize commits, branches, and changes. Here's how to get started:

  • Download and install GitKraken.
  • Log in with your GitHub account.
  • Open your repository in GitKraken to see all your commits visually.

GitKraken Interface


5. Working with Branches

Create a New Branch

In Git, branches allow you to work on different features without affecting the main codebase.

To create a new branch, use:

git switch -c <branch-name>

Or in GitKraken, click Create Branch and enter the branch name.

Switching Branches

Switch branches to work on different features:

git switch <branch-name>

Creating a New Branch in GitKraken


6. Pushing and Pulling Code to GitHub

Push Changes

To push your changes to a remote repository, first create a GitHub repository. Then, add the remote repository URL:

git remote add origin <repository-url>
git push -u origin master

Pull Changes

To pull changes from GitHub:

git pull origin master

Pushing Code to GitHub


7. Merging and Resolving Merge Conflicts

When working with multiple branches, you may need to merge them. Here's how to do it:

Checkout the branch you want to merge into (usually master):

git switch master

Merge the feature branch into master:

git merge <feature-branch>

Resolving Merge Conflicts

If there are conflicts, GitKraken helps you resolve them visually. You can accept incoming changes, keep the current changes, or merge both manually.

Merging and Resolving Merge Conflicts


8. Using AI Features in GitKraken

GitKraken offers AI-assisted commit message generation and commit reorganization, making it easier to maintain clean and efficient commit histories. For example, you can use AI to generate meaningful commit messages or recompose multiple commits into one.

AI-Assisted Commit Messages


Additional GitKraken Features

GitKraken is packed with powerful features to enhance your Git workflow beyond the basics. Here are some key ones:

Interactive Rebase

Easily reorder, edit, or squash commits with a visual drag-and-drop interface. This helps clean up your commit history before merging.

Fuzzy Finder

Quickly search and navigate through your repository files, commits, and branches using fuzzy matching.

Git LFS Support

Handle large files efficiently with Git Large File Storage integration, keeping your repository lightweight.

Pull Request Management

Create, review, and merge pull requests directly within GitKraken, integrated with GitHub, GitLab, and Bitbucket.

Issue Tracking

Link commits to issues and track progress on projects with built-in issue management.

Timelines

View a chronological timeline of your repository's activity, including commits, merges, and branch creations.

Multiple Profiles

Switch between different Git identities and configurations for personal and work projects.

Integrations and Extensions

Connect with various tools like Jira, Trello, Slack, and more for seamless project management.

Dark Mode and Themes

Customize the interface with dark mode or various themes for comfortable coding sessions.

Git Hooks

Manage and visualize Git hooks to automate tasks like pre-commit checks or post-merge actions.

These features make GitKraken a comprehensive tool for both beginners and advanced users, streamlining complex Git operations.


Advanced Git Operations

Squashing Commits

If you have too many commits, combine them into one for a cleaner history:

git reset --soft HEAD~<number-of-commits>
git commit -m "combined message"
git push --force

Cherry-Picking Commits

Copy a specific commit from another branch:

git log  # Find the commit hash
git cherry-pick <commit-hash>

Rebasing Branches

Update your branch without a merge commit:

git pull --rebase

If conflicts arise:

  1. Fix the conflicts
  2. Stage the files: git add <files>
  3. Continue: git rebase --continue
  4. Push: git push --force

To abort: git rebase --abort


Emergency Fixes

Reverting Pushed Commits

Undo a commit safely by creating a new commit that reverses it:

git revert <commit-hash>
git push

Hard Reset to Match Another Branch

Make your branch identical to another (destructive):

git reset --hard origin/<other-branch-name>

Warning: This deletes all uncommitted changes!

Removing Recent Commits Permanently

Delete the last few commits:

git reset --hard HEAD~<number-of-commits>
git push --force

Warning: This cannot be undone!

Recovering Lost Commits

Use the reflog to find and restore deleted commits:

git reflog
git cherry-pick <commit-hash>

Quick Reference

# Check status
git status

# Stage and commit all changes
git add .
git commit -m "message"
git push

# Pull latest changes
git pull

# Create and switch to a new branch
git switch -c <branch-name>

# Switch branches
git switch <branch-name>

# Undo all changes
git restore .

# Stash work temporarily
git stash
git stash pop

Troubleshooting

Branch Diverged

When your branch has diverged from the remote:

git pull --rebase

Merge Conflicts

Resolve manually:

  • Edit the conflicting files
  • Remove conflict markers (<<<<<<<, =======, >>>>>>>)
  • Stage: git add <file>
  • Continue: git merge --continue

Permission Denied

  • Verify your credentials
  • Ensure you have access to the repository

This is my personalized Git guide with GitKraken integration!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors