Collaborating with Git and GitHub -- partial update

Collaborating on GitHub requires careful management to ensure that updates to a repository reflect specific, targeted changes. A structured workflow is crucial for maintaining an organized repository and minimizing conflicts. Here’s a step-by-step guide to streamline your collaboration process.

1. Fork and Clone the Repositor

Begin by forking the target repository and then cloning it to your local machine:

1
git clone https://github.com/your-organization/your-repository.git

2. Set Up Git Configuration

Configure your Git user information. This is important for attribution of your contributions:

1
2
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

3. Create a New Branch

It’s best practice to create a new branch for each feature or bug fix. This keeps changes organized and isolated:

1
git checkout -b feature/your-feature-name

This is a shorthand for:

1
2
git branch feature/your-feature-name
git checkout feature/your-feature-name

4. Making change and committing changes

Check your changes and stage them for a commit:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#check status
git status

# add files
git add filename1 filename2

# or to add all changed files
git add .

# Commit the staged changes with a descriptive message:
git commit -m "Description of the changes made"

# if you work on vim editor
git commit -v 

5. Pushing Changes

Push your changes to the remote repository:

1
2
3
git push
# or to set the upstream branch
git push --set-upstream origin feature/your-feature-name

6. Creating a Pull Request

  • On GitHub, navigate to the repository and click on “Pull requests”.
  • Click “New pull request”, select their branch from the dropdown, and click “Create pull request”.
  • Fill out the title and description, then click “Create pull request”.

7. Addressing Feedback

Team members might provide feedback on the pull request. They can make additional changes on their local machine on the same branch, stage, commit, and push those changes. The pull request will update automatically

1
2
3
4
# Make additional changes, then:
git add .
git commit -m "Addressing feedback"
git push

8. Merging the Pull Request

Once the pull request has been reviewed and approved, it can be merged on GitHub. Click “Merge pull request” then “Confirm merge”.

9. Syncing Local Repository

After the pull request has been merged, they should sync their local repository with the remote repository to get the latest changes:

1
2
3
4
    # Switch to the main or development branch
    git checkout main
    # Pull the latest changes
    git pull

Keeping Your Repository Up-to-Date

Before starting any new changes, ensure your local repository is synchronized with the upstream repository:

  1. Sync your fork:
1
2
3
4
    git remote -v // check the remote setting
    git set-url upstream // using this command if you want to chang to another url.
    git fetch upstream
    git merge upstream/master
  1. Push synced changes to: git push origin master

Additional tips

  • View commit history with git log --oneline. Discard local changes with git reset or git checkout. Reset to a specific commit with git reset --hard origin/master

By following these steps, you can efficiently collaborate on projects using Git and GitHub while keeping your repository clean and organized.

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
© 2020 Lingyun Yang
Built with Hugo
Theme Stack designed by Jimmy