Published on

Git PR Guide

Authors
  • avatar
    Name
    Jaehyeok, Yu
    Twitter
Table of Contents

Git Pull & Push & Pull Request (PR)

To pull changes from a remote repository and push local changes to the remote repository, you can use the following commands:

To pull changes from the remote repository:

git clone <fork>
git init
git remote add origin  https://github.com/woker001/data-science-study.git
git remote add upstream https://github.com/woker001/data-science-study.git
git remote -v
git checkout master
git pull upstream master
git checkout -b dev

The provided commands are a series of Git commands that set up and configure a local repository and connect it to both the forked remote repository (origin) and the original remote repository (upstream). Here's a brief explanation of each command:

  1. git clone <fork>: This command creates a new local repository by cloning the specified forked remote repository. The <fork> represents the URL or name of the forked repository.

  2. git init: This command initializes a new Git repository in the current directory if it was not already a Git repository.

  3. git remote add origin https://github.com/woker001/data-science-study.git: This command adds a remote named origin and associates it with the forked remote repository URL. It sets up the connection between the local repository and the forked remote repository.

  4. git remote add upstream https://github.com/woker001/data-science-study.git: This command adds another remote named upstream and associates it with the original remote repository URL. It sets up the connection between the local repository and the original remote repository.

  5. git remote -v: This command displays a list of all the remotes associated with the local repository along with their URLs.

  6. git checkout master: This command switches the current branch to master, assuming that the master branch already exists in the remote repositories.

  7. git pull upstream master: This command pulls the latest changes from the master branch of the original remote repository (upstream) into the local master branch.

  8. git checkout -b dev: This command creates a new branch named dev and switches the current branch to the newly created dev branch.

After executing these commands, you will have set up a new local repository, connected it to both the forked and original remote repositories, and created a new branch named dev from the latest state of the master branch in the original remote repository. You can start making changes and working on the dev branch.

git status
git add .
git commit -m "messages"
git push origin dev
git push origin master

git checkout master
git branch -D <branch>
git push origin --delete <branch>
  • The provided commands are a series of Git commands commonly used to update a Git repository. Here's a brief explanation of each command:

  • git status: This command displays the current status of the repository, showing any changes made to tracked files and untracked files.

  • git add .: This command stages all the changes in the working directory for the next commit. The dot (.) represents all the files in the current directory and its subdirectories.

  • git commit -m "messages": This command creates a new commit with the changes that were staged in the previous step. The -m flag is used to add a commit message, which provides a brief description of the changes made in the commit.

  • git push origin dev: This command pushes the changes from the local dev branch to the remote repository on the origin remote. The origin is typically the default name for the remote repository from which the clone was made.

  • git push origin master: This command pushes the changes from the local master branch to the remote repository on the origin remote. This updates the master branch on the remote with the latest changes made in the local master branch.

Please note that the order of the commands is important. Typically, you would perform git status, git add ., and git commit in sequence to create a new commit with your changes. Then, you can push the changes to the respective branches on the remote repository using git push. Make sure you are on the correct branch before executing the git push commands.

upstream, origin

The command git remote add upstream https://github.com/woker001/data-science-study.git serves the following purpose:

  1. git remote: This is a Git command used to manage remote repositories. A remote repository is a version of your project that is hosted on a remote server, typically on a platform like GitHub.
  2. add upstream: This part of the command adds a new remote repository with the name "upstream". "upstream" is just a conventionally used name, and you can choose a different name if you prefer.
  3. https://github.com/woker001/data-science-study.git: This is the URL of the remote repository that you want to add as the "upstream" remote. In this case, it's the URL of the original repository from which your fork was made. By adding the "upstream" remote, you can now fetch changes from the original repository into your local repository. This allows you to stay up-to-date with the latest changes in the original repository and easily incorporate them into your forked repository. For example, you can use git pull upstream master to pull the latest changes from the original repository's master branch into your local master branch. This is helpful when you want to keep your fork synced with the latest changes in the original project.

Git GUI

For a more user-friendly and visual approach to managing pull requests, you can use the built-in tools provided by popular code editors like Visual Studio Code (VSC) and PyCharm.

  1. Visual Studio Code (VSC):

    • Git Graph Extension: VSC has a powerful extension called "Git Graph" that provides a visual representation of your Git repository's history and branches. It allows you to view, create, and manage branches and pull requests right from the editor.
      • Install the "Git Graph" extension from the Visual Studio Code Marketplace.
      • Open your Git repository in VSC.
      • Click on the Git Graph icon in the activity bar on the left side of the editor.
      • You will see a visual representation of your repository's history and branches.
      • To create a pull request, right-click on the branch you want to merge and select "Create Pull Request" from the context menu.
      • Fill in the pull request details, review the changes, and click "Create Pull Request" to initiate the pull request.
  2. PyCharm:

    • PyCharm has built-in support for Git, including pull request management.
    • Open your Git repository in PyCharm.
    • In the "Version Control" tool window, you will see a list of branches.
    • Right-click on the branch you want to merge and select "Create Pull Request" or "Show Pull Requests" from the context menu.
    • If you select "Create Pull Request," you will be redirected to the repository on the respective Git hosting platform (e.g., GitHub, GitLab) to complete the pull request.
    • If you select "Show Pull Requests," you will see a list of open pull requests for the repository. You can review and manage them from there.

Both VSC and PyCharm provide a more user-friendly interface for handling pull requests and other Git-related operations. They offer an intuitive way to visualize your repository's history and branches, making it easier to manage your codebase and collaborate with others. Choose the one that best suits your workflow and preferences.

Git Terminologies

Here are the Git terminologies provided in English, consolidating duplicate descriptions:

  1. Clone: The process of creating a local copy of a remote repository on your computer.

  2. Fetch: The process of downloading changes from a remote repository to your local repository without merging them.

  3. Pull: The process of downloading changes from a remote repository and automatically merging them into your local branch.

  4. Push: The process of uploading your local changes to a remote repository.

  5. Remote: A reference to a remote repository, typically stored on a server, where your code is stored and can be shared with others.

  6. Origin: The default name for the remote repository from which the local repository was cloned.

  7. HEAD: A reference to the latest commit in the current branch.

  8. Tag: A label that points to a specific commit, often used to mark important versions or releases.

  9. Stash: A feature that allows you to save changes that are not ready to be committed yet, so you can switch to another branch.

  10. Merge Conflict: A situation where Git is unable to automatically merge changes from different branches, requiring manual intervention.

  11. Rebase: The process of moving or combining a sequence of commits to a new base commit, often used to keep a clean and linear history.

  12. Cherry-pick: The process of applying a specific commit from one branch to another.

  13. Fork: A copy of a repository that allows you to freely experiment and make changes without affecting the original repository.

  14. Pull Request (PR): A formal request to merge changes from one repository or branch into another.

  15. Issue: A feature used to track tasks, enhancements, and bugs for a repository.

  16. Contributor: A person who makes contributions to a project by submitting code changes, bug reports, or other improvements.

  17. Commit Message: A brief description of the changes made in a commit, typically written in the imperative mood.

  18. Merge Commit: A commit that results from merging two or more branches together.

  19. Branching Strategy: A set of rules and guidelines for creating and managing branches in a repository.

  20. Pull Request Review: A process where other team members review and provide feedback on a pull request before it is merged.

  21. Submodule: A Git repository embedded inside another Git repository, allowing you to include external code as a dependency.

  22. Reflog: A log that records the history of branch references, useful for recovering lost commits.

  23. Bare Repository: A repository without a working directory, used for sharing code with others and for remote repositories.

  24. Gitignore: A file that specifies which files and directories should be excluded from version control.

  25. Amend: The process of adding changes to the most recent commit without creating a new commit.

  26. Remote Tracking Branch: A local copy of a remote branch used to track changes in the remote repository.

  27. Detached HEAD: A state where HEAD points directly to a commit instead of a branch, typically occurs when checking out a specific commit.

  28. Revert: The process of undoing a commit by creating a new commit that undoes the changes made in the original commit.

  29. Rebase Interactive: A more advanced rebase operation that allows you to reorder, edit, or squash commits interactively.

  30. Patch: A format used to represent changes made to code, often used for sharing and applying specific sets of changes.

  31. Fast-Forward: A type of merge where Git can directly move the branch pointer forward to the target branch without creating a merge commit.

  32. Conflict Resolution: The process of manually resolving conflicts that occur when merging or rebasing branches with conflicting changes.

  33. Git Hooks: Custom scripts that can be triggered at specific points in Git's workflow, allowing you to automate certain tasks.

  34. Patch Set: A single set of changes in a pull request or code review, often represented as a single commit.

  35. Ref: A reference to an object in Git's version control system, such as a branch, tag, or commit.

  36. Merge Base: The common ancestor commit between two branches, used as the starting point for merging changes.

  37. Reset: The process of moving the current branch pointer to a specific commit, effectively undoing commits.

  38. Squash: A type of merge or rebase operation that combines multiple commits into a single commit.

  39. Changelog: A file that contains a summary of changes made to the project, typically used for documenting releases.

  40. Git Clean: A command that removes untracked files and directories from the working directory.

  41. Git Pull Rebase: A combination of the git pull and git rebase commands, used to update a branch with changes from the remote repository while keeping a linear history.

  42. Bisect: A process used to find the commit that introduced a bug by performing a binary search through the commit history.

  43. Blame: A command that shows who last modified each line of a file, useful for identifying the author of specific changes.

  44. Committer: The person who actually made the commit, which may differ from the author if the commit was made on behalf of someone else.

  45. Shallow Clone: A clone that contains only the most recent commit history, useful for reducing the size of large repositories.

  46. Cherry-pick Range: The process of applying a range of commits from one branch to another.

  47. Subtree Merge: A merge strategy that allows you to merge a subdirectory of one repository into a subdirectory of another repository.

  48. Rebase Onto: A rebase operation that moves a branch onto a different branch or commit.

  49. Ancestor: A commit that is the parent of another commit or the common ancestor of multiple branches.

  50. Gitflow Workflow: A branching model that defines specific branches for different stages of development, including feature branches, release branches, and hotfix branches.

  51. Submodule Update: A process of updating submodules in a repository to the latest version.

  52. Interactive Staging: The process of selectively staging changes in a file, allowing you to choose which changes to include in the next commit.

  53. Repository Fork: A copy of a repository that allows you to freely experiment and make changes without affecting the original repository.

  54. Change Log: A file or document that tracks changes made to a project, typically used for documenting release notes and updates.

  55. Revert: The process of creating a new commit that

undoes the changes introduced by a previous commit.

  1. Squash and Merge: A type of merge that combines all changes from a feature branch into a single commit when merging into the target branch.

  2. Tag: A label or marker that points to a specific commit, often used to mark important points in the commit history, such as releases.

  3. Commit Message: The descriptive text that accompanies a commit, providing a summary of the changes made.

  4. Head: A reference to the latest commit in the current branch.

  5. Stash: A command that allows you to save changes in a temporary area without committing them, useful for switching branches without losing work.

  6. Rebase Interactive: A process of interactively editing, squashing, or reordering commits during a rebase operation.

  7. Pre-Commit Hook: A Git hook that runs before a commit is made, allowing you to perform checks or validations.

  8. Post-Commit Hook: A Git hook that runs after a commit is made, useful for triggering additional actions.

  9. Pre-Push Hook: A Git hook that runs before pushing changes to a remote repository.

  10. Post-Push Hook: A Git hook that runs after pushing changes to a remote repository.

  11. Bare Clone: A clone of a repository without the default working directory, used for creating a new remote repository.

  12. Ancestor: A commit that is the parent of another commit or the common ancestor of multiple branches.

  13. Reflog: A command that shows the history of HEAD references and helps recover lost commits.

  14. Garbage Collection: A process that cleans up unnecessary data and optimizes the Git repository.

  15. Shallow Clone: A partial clone that only includes a limited number of commits in the history.

  16. Git Hooks: Custom scripts or programs triggered by specific Git actions, such as pre-commit or post-receive.

  17. Git Object Types: The four types of objects in Git: blobs, trees, commits, and tags.

  18. Submodule: A repository embedded as a subdirectory within another repository.

  19. Fast-Forward Merge: A type of merge that automatically moves the branch pointer forward.

  20. Merge Conflict: A situation where Git cannot automatically resolve conflicting changes during a merge.

  21. Push: The process of uploading local changes to a remote repository.

  22. Pull: The process of fetching and merging changes from a remote repository into the current branch.

  23. Merge Commit: A commit created when merging two branches, representing the merge result.

  24. Rebase Commit: A commit created when rebasing a branch onto another branch, representing the rebased changes.

  25. Fork & Clone: The process of creating a copy (fork) of a repository and then downloading it to the local machine (clone).

  26. Tagging: The practice of assigning meaningful labels to specific commits to mark important points in the history.