0% found this document useful (0 votes)
54 views50 pages

GIT Dia5

This document discusses remote repositories in Git. It explains that a remote is a shorthand name for a Git URL that references another repository. It describes how to add, remove, and list remotes. It also covers common commands like git fetch, git pull, and git push that interact with remote repositories. Finally, it discusses tracking branches and how they are used to follow changes from another repository.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views50 pages

GIT Dia5

This document discusses remote repositories in Git. It explains that a remote is a shorthand name for a Git URL that references another repository. It describes how to add, remove, and list remotes. It also covers common commands like git fetch, git pull, and git push that interact with remote repositories. Finally, it discusses tracking branches and how they are used to follow changes from another repository.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Curso de Git

REMOTE REPOSITORIES
What is a remote

Me

Remotes
Nice to meet you!
Create a repository

You can create or clone a Git repository:


§  Create

$ git init

§  Clone

$ git clone <remote-url>


Create a repository

Clone a repo:
Concepts

A remote repository is a reference to another


repository.

A remote is a shorthand name for a Git URL.

You can define any number of remotes in a


repository
Remotes

Git uses remote and tracking branch to reference


and facilitate the “connection” to another
repository.

$ git remote: to manipulate remotes


Remotes

$ git remote

add: adds a remote


rm: deletes a remote
rename: rename a remote repo
-v: list all remotes
Remotes

In addition to git clone , other common Git commands that


refer to remote repositories are:

§  git fetch: Retrieves objects and their related metadata


from a remote repository

§  git pull: Fetch + Merge

§  git push: Transfers objects and their related metadata to


a remote repository
Tracking branches

Used exclusively to follow the changes from


another repository.

Not merge or make commits onto a tracking


branch
Tracking branches

$ git fetch <remote-repo>

$ git checkout --track –b <local-branch> <remote-


repo> / <remote-branch>
Push to a remote branches

Push

$ git push <repo> <branch>

Force Push

$ git push –f <repo> <branch>

¡Be careful forcing the push!


Fetch

$ git fetch <repo> <branch>


Merge

$ git merge <branch>

New  commit  is  created  


Pull

$ git pull <repo> <branch>

Git Fetch + Git Merge à Exactly the same as


doing separated
Pull remote branches

When you clone a repository you can only clone


the master branch.

$ git branch –a : View every branch you have got.

$ git checkout -b <local-branch> <repo>/


<remote-branch>: Pull a remote branch into a
local branch and switch it.

$ git branch <local-branch> <repo>/<remote-


branch>: Pull a remote branch into a local branch.
MERGE
What is a merge

Unifies two or more commit history branches.

Most often, a merge unites just two branches.

Git supports a merge of three, four or many


branches at the same time

All the branches to be merged must be present in


the same repository.
What is a merge

When modifications in one branch do not conflict


in another branch à new commit

When branches conflict (alter the same line) Git


does not resolve the dispute.
Merge examples

You have to switch to the target branch and


execute the merge:

$ git checkout destinyBranch

$ git merge anotherBranch


Preparing for a Merge

First of begin a merge à tidy up working directory

If you start a merge in a dirty state, Git may be


unable to combine the changes from all the
branches and those in your working directory or
index in one pass.
Merge Conflicts

Git warns you about the conflict:

And marks the file:


Locating conflicted Files

Which files have got conflicts?

Git keeps track of problematic files by marking


each one in the index as conflicted or unmerged

You can use one of these commands:


$ git status

$ git diff
Abort a merge

$ git reset --hard ORIG_HEAD


Fast Forward

A simple linear history advancement operation

Fast forward has happened in origin from B to X


Fast Forward

If another developer has pushed some changes (C,


D) you can’t push with fast forward.

You should merge your changes first.


Fast Forward Merging
TAGS
Tags vs Branches

A tag is meant to be a static name that does not


change or move over time. Once applied, you
should leave it alone.

A branch is dynamic and moves with each commit


you make. The branch name is designed to follow
your continuing development.
Tags vs Branches

You can give a branch and a tag the same name.

If you do, you will have to use their full ref names
to distinguish them.

For example, you could use refs/tags/v1.0 and


refs/heads/v1.0
Commands

$ git tag : List tags

$ git tag –a <name> -m “text to …”: Create a tag

$ git show <name>

$ git push <repo> --tags: Sends all tags


$ git push <repo> <tag-name>: Sends the tag
Types

§  Lightweight
Like a branch that doesn’t change. A pointer to a
specific commit

§  Annotated
Are stored as full objects in the Git database. They
are checksummed; contain the tagger name, email
and date. Can be signed and verified.
WORKFLOWS
Working with remotes

Forking workflow Central  Repo  

Pull  
request  

Contributor   Integrator   Contributor  


Working with remotes

Centralized workflow
Git flow

1) Two main branches: Dev & Master


Dev   Master  
Git flow

2) One feature / one branch (local)


Dev   Master  

Feature  1  
Feature  2  

Accept?  

Tag  0.1  

Accept?  
To  Prod  
Git flow

3) Every bug is fixed in an isolated branch


Dev   HoEixes   Master  
Tag  0.1  

Inserts  bug  
into  dev  
Tag  0.2  

To  Prod  
ADVANCED CONFIGURATION
Alias

Aliases can avoid typing the same command over


and over again.

Aliases were added in Git 1.4.0


Alias

Configuration:

-  Edit .git/config
[alias]
ci = commit

-  $HOME/.gitconfig: Available everywhere

-  $ git config –global alias.ci commit


Git Blame

Tells you who last modified each line of a file and


which commit made the change:

$ git blame <file>


Repository Types

There are two different types of Git repos:

-  Bare: Has no working directory. Not be used for


normal development. No direct commits.

-  Development: Typical repository. Maintains


current branch, provides checked-out copy of
the current branch in a working directory
Repository Types

Bare repo is crucial for collaborative development.

Other developers clone and fetch from the bare


repository and push updates to it

Bare  

Working  
Directory  

Other  developer   My  Computer  


Repository Types

Bare repo creation

$ git init <repository> --bare

Best Practice:

A published repository should be bare


BONUS:WORKING WITH DROPBOX
Commands

-  Create a folder into Dropbox folder


-  $ git init --bare project.git
-  Go to your project folder
-  $ git init
-  Add the remote:
-  $ git remote add repositoryName ~/Dropbox/
project.git
-  $ git commit in project folder

-  $ git push <repo> <branch>


Commands

Another developer clones the proyect:

-  $ git clone ~/Dropbox/project

-  Add remote

-  $ git pull <repo> <branch>


Preguntas

Israel  Alcázar  
[email protected]  
@ialcazar  

You might also like