Liquizar / Git_Advance_Concepts

Explore advanced Git techniques: amending commits, aliases, rebase, cherry-pick, stash, and more. Elevate your version control skills.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advanced Git Concepts Showcase

Welcome to the Advanced Git Concepts Showcase! In this repository, we'll delve into several advanced Git features that can greatly enhance your version control workflow. Below, we'll explore each concept in detail, providing examples and explanations to help you better understand and utilize these powerful Git commands.

Git Amend

The git commit --amend command allows you to make changes to the most recent commit without creating a new commit. It's useful for making small adjustments or adding forgotten files to the previous commit.

git add <file(s)>
git commit --amend

When you run git commit --amend, Git opens your default text editor with the commit message of the previous commit. You can make changes to the message if needed, then save and exit the editor to finalize the amended commit.

Git Reflog

Git reflog is a reference log that records the history of HEAD movements in the repository, including commits that are no longer referenced by any branch or tag. It's a safety net for recovering lost commits or branches, even if they seem unreachable.

git reflog
git checkout <commit_hash>

By running git reflog, you'll see a chronological list of recent HEAD movements along with their corresponding commit hashes. You can then use these commit hashes to navigate to specific points in your repository's history.

Git Squash and Merge

Git allows you to squash multiple commits into a single, coherent commit before merging them into the main branch. This helps maintain a clean and concise commit history.

git rebase -i HEAD~<number_of_commits>

When you run git rebase -i HEAD~<number_of_commits>, Git opens an interactive rebase session where you can choose which commits to squash, edit commit messages, or even reorder commits before finalizing the rebase.

Alias

Git aliasing enables you to create custom shortcuts for frequently used commands, reducing typing and improving productivity.

git config --global alias.<alias_name> <command>

For example, you can create an alias called co for checkout:

git config --global alias.co checkout

After defining the alias, you can simply use git co <branch_name> instead of git checkout <branch_name>.

Git Rebase

Git rebase is a powerful tool for integrating changes from one branch into another by reapplying each commit from the current branch onto the target branch, resulting in a linear history.

git checkout <target_branch>
git rebase <source_branch>

During a rebase, Git replays each commit from <source_branch> onto <target_branch>, one by one. If there are conflicts, Git pauses to allow you to resolve them before proceeding.

Git Cherry Pick

Git cherry-pick enables you to select specific commits from one branch and apply them onto another branch, allowing for precise integration of individual changes.

git cherry-pick <commit_hash>

By providing the commit hash of the desired commit, Git applies the changes introduced by that commit onto the current branch. This is particularly useful for applying bug fixes or feature enhancements from one branch to another.

Git Stash

Git stash temporarily shelves changes you've made to your working directory, allowing you to switch branches or perform other operations without committing unfinished work.

git stash
git stash apply

Stashing is useful when you need to switch to a different task or address an urgent issue without committing incomplete changes. Once you're ready to continue working on the stashed changes, you can apply them back to your working directory using git stash apply.

Feel free to explore and experiment with these advanced Git concepts to enhance your version control workflow. If you have any questions or need further assistance, don't hesitate to reach out!

About

Explore advanced Git techniques: amending commits, aliases, rebase, cherry-pick, stash, and more. Elevate your version control skills.