0%

Git: From Project Initialization to Code Contribution

Setup

  1. Clone the remote repository

    1
    git clone [repository URL]
  2. Nabigate to the project directory

    1
    cd [repository name]
  3. create your new local branch

    1
    git checkout -b [your-branch-name]
  4. Push your local branch to the remote repository and set that remote branch as the “upstream” for your local branch.

    1
    git push -u origin [your-branch-name]

    -u represents --set-upstream

Make code changes and commit

  1. Make Your Code Changes
    Edit the files and implement your contribution.

  2. Stage and commit Your Changes

    1
    2
    git add . or selectedfiles
    git commit -m "Describe your changes"

Update your branch to lastest version

  1. Fetch the latest changes from the remote repository

    1
    2
    git fetch
    # or git fetch origin main
  2. Update your local branch to the latest remote main version

    1
    2
    3
    4
    5
    6
    7
    #Update **local** main branch to the latest remote version
    git checkout main
    git pull

    #update your **local** branch to the latest main version
    git checkout [your-branch-name]
    git merge main

or

1
git rebase origin/main

You might handle some conflicts manually in this stage.

Submit

  1. Push your changes to the remote repository
    1
    git push 
  1. Create a pull request
    Go to the repository’s web interface (e.g., GitHub) and initiate a pull request. This will notify the maintainers of your changes, and they’ll review your contribution.

  2. Address review feedback
    If the project maintainers have feedback or request changes, make the necessary adjustments in your branch and push the updates. The pull request will automatically reflect these changes.

-------------End of blogThanks for your reading-------------