I wish I'd known these git commands earlier

I wish I'd known these git commands earlier

[30]

Introduction

Git is a free and open source distributed version control system designed to handle everything from small to large projects with speed and efficiency.

Understanding Version Control

Version Control refers to the process of saving different files or ‘versions’ throughout the various stages of a project.

Git Commands

pull

When you are finished making changes to someone else’s code, you can share them with the original owner via a ‘pull request.’

merge

Owners can add new changes to their projects via a merge.

Stashing Changes

git stash -> # Temporarily saves your uncommitted changes
git stash list -> # Lists all stashed changes
git stash apply stash@{0} -> # Applies the specified stash without removing it
git stash pop -> # Applies the most recent stash and removes it from the stash list
git stash drop stash@{0} -> # Deletes a specific stash

Working with Tags

git tag -> # Lists all tags in the repository
git tag -a v1.0 -m “Version 1.0“ -> # Creates an annotated tag with a message
git push --tags -> # Pushes all tags to the remote repository
git tag -d v1.0 -> # Deletes a tag locally 
git push origin --delete v1.0 -> # Deletes a tag from the remote repository

Cherry Picking

git cherry-pick commit-hash -> # Applies a specific commit from another branch
git cherry-pick --continue -> # Continues the cherry-pick process after resolving conflicts 
git cherry-pick --abort -> # Aborts the cherry-pick process

Working with Remotes

git remote -v -> # Lists all remote repositories and their URLs
git remote add origin https://github/com/user/repo.git -> # Adds a new remote repository
git remote remove origin -> # Removes a remote repository
git fetch origin -> # Fetches all branches and updates from the remote
git pull origin branch-name --rebase -> # Rebases the local branch with the remote branch

Git Aliases

git config --global alias.st status -> # Creates an alias for ‘git status’
git config --global alias.co checkout -> # Creates an alias for ‘git checkout’
git config --global alias.br branch -> # Creates an alias for ‘git branch’

Bisecting to find Bugs

git bisect start -> # Starts the bisect process
git bisect bad -> # Marks the current commit as bad
git bisect good commit-hash -> # Marks a specific commit as good
git bisect reset -> # Ends the bisect session and returns to the original branch

Cleaning Untracked Files

git clean -n -> # Displays the untracked files and directories that would be removed
git clean -f -> # Removes untracked files
git clean -fd -> # Removes untracked files and directories

Interactive Rebase

git rebase -i HEAD~3 -> # Opens an interactive rebase for the last three commits
# Actions during interactive rebase:
# - pick: Keep the commit as is
# - squash: Combine this commit with the previous one
# - reword: Modify the commit message
# - edit: Modify the commit 
git rebase --abort -> # Aborts the rebase process and restores the original branch
git rebase --continue -> # Continues the rebase process after resolving conflicts