12 Sharing Changes

Remember that Git is different from most traditional version control systems; committing a change and sharing that change are two distinct tasks. Committing changes is covered in detail in Task 7, Committing Changes; this task gives you a quick cheat sheet for the various tasks you need to perform to collaborate with others. For more detail on these steps, see Part IV, Working with a Team.

Once you have a local clone (see Task 4, Creating a Local Copy of an Existing Repository) or have set up a remote after initializing your repository (see Task 19, Adding and Removing Remotes), you need to fetch changes from the remote repository to keep your local branches (we’ll cover what branches are in just a second in Part III, Working with Branches) in sync using git fetch. After fetching changes, you must merge those changes using any of the methods covered in Part III. Fetching is covered in more detail in Task 20, Retrieving Remote Changes.

You can also fetch changes and merge them at the same time using git pull. It fetches the changes and then merges them into the current branch. You can specify the --rebase parameter to have Git rebase your local branch on top of the remote changes (see Task 16, Rewriting History by Rebasing). Pulling is covered in more detail in Task 21, Retrieving Remote Changes, Part II.

Sending changes back to a remote repository to share is done via the git push command. Consider it the inverse of git pull; it sends your changes to the remote repository and merges those changes into the remote branch via a fast-forward merge, which is a merge where both branches share a common ancestor and only the branch being merged in has changes in it.

Don’t worry if parts of this sound like Greek. This is a high-level overview without diving into the specifics. The next two parts are going to fill in all the missing pieces.

What To Do...
  • 1. Set up the remote repository.
    • You clone a repository. Or...

    • You add a remote to an existing repository.

  • 2a. Fetch changes from a remote repository.
     
    prompt>​ git fetch <remote name>
     
    ...​ then merge the changes into your work ...
  • 2b. Pull changes from a remote repository.
     
    prompt>​ git pull <remote name>
     
    ...​ pull from a repository you cloned ...
     
    prompt>​ git pull origin
     
    ...​ pull, but rebase your local changes on top
     
    ...​ of the remote change instead of merging them
     
    prompt>​ git pull --rebase origin <remote branch name>
  • 3. Push changes to a remote repository.
     
    prompt>​ git push <remote name> <branch name>

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.142.166