Saturday, February 24, 2018

Git: Pushing code to a remote repository


This is the second recipe in the series designed to inspire my team of user-interface-git-users to embrace the command-line. This post presents the commands used to determine which files have been changed in a repository and how to push to a remote repository.

Detecting changes to Git repository

After modifying files, deleting files or adding files to a Git repository, the git status command can be used to determine which files have been changed;

git status

Below the changes to a repository can be seen by invoking git status:

Using git status the files modified can be determined. Additional the files/directories added and deleted can be determined. The output is color code for those who can see color. Being color blind, I cannot read the non-white text above so I wrote a separate post to address the issue Git (for the color blind): Detecting changes to a repository.

Pushing code to a remote Git repository

The steps to pushing code to a remote repository are:

  • git add -- adds files in the directory or sub-directory to a staging area. Individual files or folders can also be specified.
  • git commit -- records the change to the repository (commits them locally) and includes a message to describe the purpose of the commit.
  • git push -- pushes changes from a local branch to a remote branch meaning your local changes get pushed up to the server hosting Git.

An example of the commands to run is as follows:

git add .
git commit -m "Task-335 completed"
git push origin Task-335

Invoking the command sequence above generated the following:

The "git add ." added all modified, created and delete files and directories including those in sub-directories. It is also possible add files or folders individual using "git add <filename>" and "get add <directoryname>".

 The message with commit should describe the action. Since Task-335 is completed there is not much to describe,. To see Task-335 the bug tracker can be used.

The command "git push origin Task-335" pushes the local changes from branch, Task-335, back to origin. The term "origin" refers to the cloned repository.

No comments :

Post a Comment