How to push, pull, and fetch from a remote repository using Git Bash

Home > Search > How-to
  by

Let's take an example where you want to download files from a certain repository on https://github.com. In this example, John Doe has a repository named Stage that contains one file, README.md.

 

Use the git clone URL command to download the repository.

$ git clone https://github.com/johndoe/Stage.git
Cloning into 'Stage'...
remote: Counting objects: 3 done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-resued 0
Unpacking objects: 100% (3/3), done.

 

The dir command will show that the files from https://github.com/johndoe/Stage.git have been downloaded to the local PC.

$ dir
. . . 
Stage

 

Move into the Stage directory, and then use the git remote command to determine the alias of the remote repositiory.

$ git remote
origin

 

In this example, John Doe's filles in a repository named Stage was sent to the local machine, using the alias origin.

 


Fetching

When changes are made to the files in the GitHub repository, the git fetch name or git pull name commands can be used to download the updated files from the repository to the local PC. The git fetch name command will download but not merge the files into your branch. 

$ git fetch origin

 


Pulling

The git pull name command will download and merge the files.

$ git pull origin
. . .
 README.md | 1 +
  1 file changed, 1 insertion(+)

 


Pushing

After making changes to files on your local PC, the git push name command will upload the files to the remote repository.

$ git push origin

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments