🤓
Thomas lab
Git&Github
Git&Github
  • Fetching & Pulling
  • Git alias
  • Git & Github : What is in .git ?
  • Git Rebase
  • Git reflog
  • Git Stash
  • Git tags
  • Git Workflow(Collaboration)
  • Quick High-Level
  • Git diff
  • Git installer
  • Reset & Revert commit
  • Github Collaborators
  • Github Basics
  • Introducing Git
  • Merging Branch
  • How to use multiple account
Powered by GitBook
On this page
  • Fetching & Pulling
  • Cloning
  • Remote tracking branches
  • Remote Branches
  • Context
  • You can checkout these remote branch pointers
  • You can clone anthor branch in git repo remote
  • Git Fetching
  • Git pulling

Fetching & Pulling

NextGit alias

Last updated 8 months ago

Fetching & Pulling

Cloning

What happens when clone git repositorires ?

When we clone a repository from a git repository , we will have a branch more , which provide by cloud github,gitlab etc ... it's origin/master

Discription : origin/master like a regular branch referench,We can move this around myself and we can also call it's Remote tracking branch . It's a reference to the state of the master branch on the remote . I can't move this my self.It's like a bookmar poingting to the last known commit on the master branch on origin .

Remote tracking branches

"At the time you last commuicated with this remote repository, here is when x branch was pointing" .

They follow this pattern <remote> / <branch> : - origin/master references the state of the master branch on the remote repopo named origin . - upstream/logoRedesign references the state of the the logoRedesign branch on the remote named upstream (a common remote name) .

Remote Branches

Run git branch -r to view to view the remote branches our repository knows about .

git branch -r origin/master

Context

When i run git status

it push notifications . On branch master , Your branch is ahead of 'origin/master' by 2 commits.

(use "git push" to publish your local commits)

You can checkout these remote branch pointers

git checkout origin/master

we can recive a notifications :

Note : switching to origin/master .

your are in detached head state . you can look around , make exper..

You can clone anthor branch in git repo remote

Remote branches

Once you've cloned a repository, we have all date and git history for the project at the moment in time. However,that does not mean it's all in my workspace ! .

The github repo has a branch call puppies, but when i run git branch I don't see it on my machine! All i see is the master branch . what's going on ?

`By default, my master branch is already trackiing origin/master'

I didn't connect these my my self

But i want to work on the puppies branch locally

I could checkout origin/puppies,but that puts me in detached HEAD .

I want my own local branch call puppies, and i want it to be connected to origin/puppies,just like my local master branch is connected to origin/master.

It's super easy

Run git switch <remote-branch-name> to create a new local branch form the remote branch of the same name

git switch puppies make me a local pupies branch AND sets it up to track the remote branch origin/puppies

Anthor way

git checkout --track origin/puppies 

The new command git switch makes this super easy to do .! it used to slightly more complicate using git checkout

Git Fetching

Fetching allows us to dowload changes from a remote repository,BUT those changes will not be automatically integrated into our working files

It let you see what others have been working on,without having to merge thouse change your local repo .

Think of it as "please go and get the lastest information from github . but don't not screw up working .

The git fetch <remote> command fetches branches and history from a specific repmote repository. It only updates remote tracking branches .

git fetch origin would fetch all changes from the origin remote repository .

We can also fetch a specific branch form a remote using

git fetch <Remote> <Branch>

For example, git fetch origin master would retrive the lastest information from the master branch o nthe origin remote repository.

Git pulling

git pull is another command we can use to retrieve changese from a remote repository. Unlike fetch, pull actually update our HEAD branch with whatever changes are retrieved from the remote .

"go and dowload data form Github And immediately update my local repo with thouse changes" .

git pull = git fetch  + git merge 

git pull

To pull, we specify the particular remote and branch we want to pull using git pull <remote> <branch>. Just like with git merge, it matter branch we run it from is where the changes will be merged into

git pull origin master would fetch the lastest information from the origin's master branch and merge those changes into our current branch .