-
Remote: A remote in Git refers to a repository hosted on a different server, which can be accessed and interacted with over the internet. Remotes allow collaborative development and sharing of code between multiple contributors. Common remote repositories include GitHub, GitLab, and Bitbucket.
-
Origin: "Origin" is the default name often given to the main remote repository where you cloned or originated your local repository from. It represents the remote repository's URL, and you can fetch, pull, and push changes to/from it.
-
Stage (Index): The staging area (also called the index) is where you prepare and organize changes you want to include in the next commit. It allows you to selectively add certain modifications from your working directory to the commit, rather than committing all changes at once.
-
Stash: The stash is a feature in Git that allows you to temporarily save changes that you're not ready to commit. It's useful when you need to switch to a different branch or work on something else without committing half-done work.
-
Tag: Tags in Git are markers that associate a specific point in history with a name. They're often used to label important or significant versions of your code, like releases. Unlike branches, tags don't move with new commits.
-
Commit: A commit is a snapshot of your code at a specific point in time. It records the changes you've made to your files. Each commit has a unique hash that identifies it and references the previous commit(s), forming a commit history.
-
Branch: A branch is a separate line of development in Git. It allows you to work on new features or fixes without affecting the main codebase. Branches can be merged back into the main branch (often called the "master" or "main" branch) once the changes are ready.
-
Creating a Remote and Pushing Changes:
- Create a repository on GitHub.
- Clone the remote repository to your local machine:
git clone <repository_url>
- Make changes to your local files.
- Stage the changes:
git add .
- Commit the changes:
git commit -m "Add new feature"
- Push the changes to the remote repository:
git push origin main
-
Stashing Changes:
- Make some changes but not ready to commit.
- Stash the changes:
git stash
- Switch to a different branch or perform other tasks.
- Apply the stashed changes back:
git stash apply
-
Creating and Using Tags:
- Tag a commit:
git tag v1.0
- Push the tag to the remote:
git push origin v1.0
- Checkout the tagged commit:
git checkout v1.0
- Tag a commit:
-
Working with Branches:
- Create a new branch:
git branch feature-branch
- Switch to the new branch:
git checkout feature-branch
- Make changes, stage, and commit.
- Merge changes back to main:
git checkout main
->git merge feature-branch
- Create a new branch:
git init
⭐
- Description: Initializes a new Git repository in the current directory.
git clone <repository URL>
⭐
- Description: Creates a copy of a remote repository on your local machine.
git add <file>
⭐
- Description: Stages a file, preparing it for the next commit.
git commit -m "message"
⭐
- Description: Records the staged changes as a new commit with a descriptive message.
git status
⭐
- Description: Shows the status of your working directory and staged changes.
git diff
- Description: Displays the differences between the working directory and the most recent commit.
git log
- Description: Lists the commit history in reverse chronological order.
git pull
⭐
- Description: Fetches changes from a remote repository and merges them into the current branch.
git push
⭐
- Description: Sends your committed changes to a remote repository
git branch
⭐
- Description: Lists all branches in the repository.
git checkout <branch>
⭐
- Description: Switches to a different branch.
git merge <branch>
⭐
- Description: Integrates changes from one branch into the current branch.
git remote -v
⭐
- Description: Lists the remote repositories associated with your local repository.
git fetch
⭐
- Description: Retrieves the latest changes from a remote repository without merging them.
git reset <file>
⭐
- Description: Unstages a file, reverting it back to the state before staging.
git revert <commit>
⭐
- Description: Creates a new commit that undoes the changes made in a specified commit.
git rebase <branch>
⭐
- Description: Moves the current branch's commits onto the tip of another branch.
git tag <tagname>
⭐
- Description: Creates a lightweight, named pointer to a specific commit.
git remote add <name> <URL>
⭐
- Description: Adds a new remote repository with a specified name and URL.
git remote remove <name>
- Description: Removes a remote repository from your local repository.
git stash
- Description: Temporarily stores changes that are not ready for a commit.
git stash pop
- Description: Applies the most recent stash and removes it from the stash list.
git cherry-pick <commit>
- Description: Applies the changes from a specific commit to the current branch.
git clean -n
- Description: Shows which untracked files will be removed using git clean.
git submodule update --init
- Description: Initializes and updates submodules within your repository.
git show <commit>
- Description: Displays detailed information about a specific commit.
git config --global user.name "Your Name"
- Description: Sets your global Git username.
git config --global user.email "[email protected]"
- Description: Sets your global Git email address.
git remote show <name>
- Description: Provides information about a specific remote repository.
git push --tags
- Description: Pushes all tags to the remote repository.
git log --graph
- Description: Displays the commit history with a graph showing branching and merging.
git branch -d <branch>
- Description: Deletes a local branch that has been merged.
git branch -m <newname>
- Description: Renames the current branch to .
git config --list
- Description: Lists all Git configuration settings.
git blame <file>
- Description: Shows who last modified each line of a file and when.
git pull --rebase
- Description: Fetches changes from the remote repository and rebases your changes on top.
git log --author=<author>
- Description: Displays the commit history filtered by a specific author.
git commit --amend
- Description: Edits the most recent commit message or adds changes to it.
git reflog
- Description: Lists a log of all the Git references in your repository, useful for recovering lost commits.
git bisect
- Description: Helps find the commit that introduced a bug by performing a binary search through the commit history.
git log --oneline
- Description: Displays a condensed commit history, showing each commit on a single line.
git remote rename <old-name> <new-name>
- Description: Renames a remote repository's name.
git remote set-url <name> <new-URL>
- Description: Changes the URL of a remote repository.
git pull <remote> <branch>
- Description: Fetches and merges changes from a specific remote branch into the current local branch.
git push <remote> <branch>
- Description: Pushes changes to a specific remote branch.
git log --since=<time>
- Description: Displays commits made since a specific time or date.
git log --until=<time>
- Description: Displays commits made until a specific time or date.
git blame -L <start>,<end> <file>
- Description: Annotates only the specified lines of a file with commit and author information.
git cherry-pick -n <commit>
- Description: Applies changes from a commit without committing, allowing for selective modifications before committing.
git clean -f
- Description: Removes untracked files from the working directory. Use with caution.
git revert -n <commit>
- Description: Reverts changes from a commit without creating a new commit. Allows for further modifications before committing.
git reset --soft <commit>
- Description: Resets the current branch's HEAD to a specific commit, keeping changes staged for commit.
git reset --hard <commit>
- Description: Resets the current branch's HEAD to a specific commit, discarding all changes after that commit.
git stash save "message"
- Description: Stashes changes with a descriptive message for easy identification later.
git stash list
- Description: Lists all stashes that have been saved.
git stash apply <stash>
- Description: Applies changes from a specific stash to the working directory without removing the stash.
git stash drop <stash>
- Description: Deletes a specific stash, discarding its changes permanently.
git submodule update --recursive
- Description: Recursively initializes and updates submodules, including submodules' submodules.
git log --grep=<pattern>
- Description: Filters the commit history to show only commits with messages matching the specified pattern.
git log -<file>
- Description: Displays the commit history for a specific file.61. git tag -a -m "message"
- Description: Creates an annotated tag with a message for a specific commit.
git push <remote> --delete <branch>
- Description: Deletes a remote branch.
git fetch --prune
- Description: Fetches changes from a remote repository and removes references to remote branches that no longer exist.
git clean -df
- Description: Removes untracked files and directories forcefully. Use with caution.
git diff <commit1>..<commit2>
- Description: Shows the differences between two specific commits.
git log --pretty=format:"%h %an, %ar : %s"
- Description: Customizes the format of the commit history display.
git config --global core.editor "editor-name"
- Description: Sets the default text editor for Git commit messages.
git remote prune <remote>
- Description: Removes remote tracking references for branches that have been deleted on the remote repository.
git reset HEAD~<n>
- Description: Moves the current branch and HEAD back by commits.
git log --no-merges
git branch -a
- Description: Lists all local and remote branches.
git commit -a -m "message"
- Description: Stages and commits all changes in tracked files in one command.
git log -p
- Description: Shows commit history along with the detailed diff of each commit.
git log --author-date-order
- Description: Displays commit history in chronological order based on author date.
git blame -C <file>
- Description: Annotates a file, tracking both content and rename history.
git bisect start
- Description: Initiates the binary search for a bug using the bisect functionality.
git bisect good <commit>
- Description: Marks a commit as "good" during a bisect operation.
git bisect bad <commit>
- Description: Marks a commit as "bad" during a bisect operation.
git bisect reset
- Description: Exits the bisect operation, returning to the original state.
git cherry -v <upstream> <branch>
- Description: Lists commits in a branch that haven't been merged into the upstream branch.
git clean -fdx
- Description: Removes untracked files, directories, and ignored files forcefully.
git log --first-parent
- Description: Displays commit history considering only the first parent in merge commits.
git commit --amend --no-edit
- Description: Adds staged changes to the previous commit without changing the commit message.
git rebase -i <commit>
- Description: Initiates an interactive rebase, allowing you to squash, edit, or reorder commits.
git diff --cached
- Description: Shows the differences between staged changes and the last commit.
git config --global alias.<alias-name> "<git-command>"
- Description: Creates a custom alias for a frequently used Git command.
git log --name-status
- Description: Shows the commit history along with the list of changed files and their status.
git stash clear
- Description: Removes all stashed changes.
git log --decorate
- Description: Displays additional information (tags, branches) about commits.
git config --global core.autocrlf <value>
- Description: Configures line-ending settings for cross-platform compatibility.
git shortlog
- Description: Summarizes commit history, showing the author's name and commit count.
git log --merges
- Description: Lists only merge commits in the commit history.
git reflog expire --expire=<time>
- Description: Removes entries from the reflog older than a specified time.
git update-index --assume-unchanged <file>
- Description: Marks a file as unchanged, even if it is modified.
git update-index --no-assume-unchanged <file>
- Description: Reverts the --assume-unchanged status of a file.
git clean -i
- Description: Interactively selects untracked files to be removed.
git grep <pattern>
- Description: Searches for a specific pattern in the contents of files in the repository.
git commit --fixup=<commit>
- Description: Creates a commit that fixes or addresses a specific commit.
git commit --squash=<commit>
- Description: Squashes changes from a specific commit into the current commit.
git ls-tree <commit>
- Description: Lists the contents of a commit, showing file names and modes.