banner



How To Share Private Github Repo

Collaborating

Overview

Teaching: 25 min
Exercises: 0 min

Questions

  • How can I use version command to collaborate with other people?

Objectives

  • Clone a remote repository.

  • Collaborate past pushing to a mutual repository.

  • Describe the basic collaborative workflow.

For the next step, go into pairs. One person will be the "Possessor" and the other will be the "Collaborator". The goal is that the Collaborator add together changes into the Possessor's repository. Nosotros volition switch roles at the end, and so both persons will play Owner and Collaborator.

Practicing By Yourself

If you're working through this lesson on your own, you can carry on by opening a second terminal window. This window volition represent your partner, working on some other reckoner. Y'all won't need to give anyone access on GitHub, because both 'partners' are you.

The Owner needs to give the Collaborator access. On GitHub, click the settings button on the right, select Manage access, click Invite a collaborator, and so enter your partner's username.

Adding Collaborators on GitHub

To take admission to the Possessor's repo, the Collaborator needs to become to https://github.com/notifications or check for email notification. One time there she tin accept access to the Owner'southward repo.

Next, the Collaborator needs to download a copy of the Owner'due south repository to her machine. This is called "cloning a repo".

The Collaborator doesn't want to overwrite her own version of planets.git, and then needs to clone the Possessor's repository to a different location than her own repository with the same name.

To clone the Possessor's repo into her Desktop folder, the Collaborator enters:

                          $              git clone git@github.com:vlad/planets.git ~/Desktop/vlad-planets                      

Replace 'vlad' with the Possessor'southward username.

If you choose to clone without the clone path (~/Desktop/vlad-planets) specified at the terminate, yous will clone inside your ain planets binder! Make sure to navigate to the Desktop binder first.

After Creating Clone of Repository

The Collaborator can at present make a modify in her clone of the Owner's repository, exactly the same way as we've been doing earlier:

                          $                            cd              ~/Desktop/vlad-planets              $              nano pluto.txt              $                            cat              pluto.txt                      
                          $              git add together pluto.txt              $              git commit              -yard              "Add together notes virtually Pluto"                      
                          one file changed, 1 insertion(+)  create mode 100644 pluto.txt                      

And then button the change to the Possessor's repository on GitHub:

            Enumerating objects: 4, done. Counting objects: 4, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/iii), 306 bytes, done. Full three (delta 0), reused 0 (delta 0) To https://github.com/vlad/planets.git    9272da5..29aba7c  main -> primary                      

Note that we didn't accept to create a remote called origin: Git uses this name past default when we clone a repository. (This is why origin was a sensible choice earlier when nosotros were setting upward remotes past hand.)

Take a expect at the Owner's repository on GitHub again, and you should be able to run across the new commit made by the Collaborator. You may need to refresh your browser to see the new commit.

Some more about remotes

In this episode and the previous 1, our local repository has had a single "remote", chosen origin. A remote is a re-create of the repository that is hosted somewhere else, that we tin push to and pull from, and there's no reason that you accept to work with only i. For example, on some big projects you might have your own re-create in your own GitHub account (you'd probably call this origin) and as well the main "upstream" projection repository (let's telephone call this upstream for the sake of examples). You lot would pull from upstream from fourth dimension to time to get the latest updates that other people have committed.

Remember that the name you give to a remote simply exists locally. It's an allonym that you choose - whether origin, or upstream, or fred - and not something intrinstic to the remote repository.

The git remote family of commands is used to fix and change the remotes associated with a repository. Hither are some of the most useful ones:

  • git remote -v lists all the remotes that are configured (nosotros already used this in the last episode)
  • git remote add together [name] [url] is used to add a new remote
  • git remote remove [name] removes a remote. Note that it doesn't touch on the remote repository at all - it just removes the link to information technology from the local repo.
  • git remote set-url [name] [newurl] changes the URL that is associated with the remote. This is useful if information technology has moved, e.g. to a different GitHub account, or from GitHub to a different hosting service. Or, if we made a typo when adding it!
  • git remote rename [oldname] [newname] changes the local allonym by which a remote is known - its proper name. For example, one could apply this to change upstream to fred.

To download the Collaborator'south changes from GitHub, the Owner now enters:

            remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/four), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/three), done. From https://github.com/vlad/planets  * branch            primary     -> FETCH_HEAD    9272da5..29aba7c  main     -> origin/main Updating 9272da5..29aba7c Fast-forward  pluto.txt | 1 +  ane file changed, 1 insertion(+)  create mode 100644 pluto.txt                      

Now the three repositories (Owner's local, Collaborator's local, and Possessor's on GitHub) are back in sync.

A Bones Collaborative Workflow

In practise, information technology is good to be sure that you take an updated version of the repository you are collaborating on, so yous should git pull earlier making our changes. The basic collaborative workflow would be:

  • update your local repo with git pull origin chief,
  • make your changes and stage them with git add,
  • commit your changes with git commit -m, and
  • upload the changes to GitHub with git button origin main

Information technology is meliorate to make many commits with smaller changes rather than of ane commit with massive changes: small commits are easier to read and review.

Switch Roles and Repeat

Switch roles and repeat the whole process.

Review Changes

The Owner pushed commits to the repository without giving whatever information to the Collaborator. How tin can the Collaborator notice out what has changed with command line? And on GitHub?

Solution

On the command line, the Collaborator tin can use git fetch origin main to get the remote changes into the local repository, just without merging them. Then by running git diff main origin/primary the Collaborator volition come across the changes output in the terminal.

On GitHub, the Collaborator can get to the repository and click on "commits" to view the about recent commits pushed to the repository.

The Collaborator has some questions about one line change made past the Possessor and has some suggestions to propose.

With GitHub, information technology is possible to comment the diff of a commit. Over the line of code to annotate, a blue comment icon appears to open up a comment window.

The Collaborator posts its comments and suggestions using GitHub interface.

Version History, Fill-in, and Version Control

Some backup software can keep a history of the versions of your files. They also allows you lot to recover specific versions. How is this functionality different from version control? What are some of the benefits of using version control, Git and GitHub?

Key Points

  • git clone copies a remote repository to create a local repository with a remote chosen origin automatically set upwards.

Source: https://swcarpentry.github.io/git-novice/08-collab/index.html

0 Response to "How To Share Private Github Repo"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel