This is a brief tutorial on how to download source code from a remote git repository and make changes on a specific branch. As use case, GitHub allows the creation of a web-site along with the main project. Web-site source code is stored in the same repository, but on another branch named gh-page.

Through this tutorial, you will be able to:

  • download the source code from remote git repository;
  • make changes to the source code, commit and push these changes.

Local repository initialisation

Let's create a directory for the source code and init the git repository:

# mkdir projbranch-website
# cd projbranch-website
projbranch-website# git init

Now the git is initialised, indeed a new hidden directory .git has been created within the project directory. Of course, Git at the moment is not attached to any remote repository. Let's provide the url of the remote origin; it is a remote server that contains the project source code organised in multiple branches. The url provided in the git remote add is the url of your project, if it is on github, usually it is

Source code download

# git remote add origin https://yourprojectaddress

The next step is to download all the source code; and in case of git, it will download all the branches in a local repository.

# git pull

The source code is locally stored. Now let's select the branch performing a checkout, specifying the
name of the branch. As example, GitHub allows the creation of a web-site along with the project. The web-site source code in another branch name gh-page; so in order to change it, you need to select and work on this branch.

# git checkout yourbranch

Now, you can make any change to the source code.

Commit the changes

I suggest to check any time the changes you made in the repository before the commit. A git status is the right command to use for this.

# git status

It is very useful, because it lists the changed/untracked files, using different colours, usually red for the changed files. The next step is to add files to the local git index. In the following command line all the changed files are added to the git index, but with the same git add is possible to add only some files.

# git add .

In order to commit the changes let's use the git commit command as usual.

# git commit -m "Your message which explains what changes you made."

Now the changes are on the local repository, but not on the remote repository. We need to do a push of the commits as the following.

# git push origin gh-pages
Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>