BookmarkSubscribeRSS Feed

DevOps Applied to SAS Viya 3.5: Top Git Commands with Examples

Started ‎04-13-2020 by
Modified ‎07-19-2021 by
Views 5,144

Today, Git is effectively the de-facto standard for software version control, and it is truly an expected tool in every developer’s toolbox. Whether you are working with GitHub or GitLab, sooner or later you will need to use git commands. Here are the Git commands we will cover: git clone, git checkout, git add, git status, git commit, git log, git push, git remote, git pull, git branch.




GitHub Credentials and GitHub Project

You need a GitHub user and password.


You need a git repository. To follow the examples two projects are provided:



Two variables will be used, {your-user} and {your-user-branch} . Replace them with your GitHub user.


Fork an existing repository

A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. Go to



From top right, press Fork. Sign-in if necessary.

The project becomes{your-user}/git-demo e.g. , for my user.

The screenshots in the post are taken while working with this project.


A SAS Viya Machine

You also need a SAS Viya Machine (SAS Viya 3.5 used in this post).


Connect with MobaXterm to the viya host (sasviya01 machine, in my example).

Create a folder under $HOME and grant rights to this folder.


cd $HOME
mkdir $HOME/devops
chmod -R 755 devops
cd devops
ls -l

You should see:

total 0

In my case, the environment variables correspond to:$USER = sbxbot and $HOME = /home/sbxbot


git clone

Usage: git clone [url]  

Clone an existing repository from a URL on the local machine. One of the most used commands.

Inside /devops folder:

git clone{your-user}/git-demo.git

e.g. git clone 

Cloning into 'git-demo'...
remote: Enumerating objects: 32, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 32 (delta 5), reused 29 (delta 4), pack-reused 0
Unpacking objects: 100% (32/32), done.


Confirm cloning

cd $HOME/devops/git-demo/Data-Management/scripts/
ls -l

You should see a CAS script from the cloned remote repository.

total 4
-rw-r--r--. 1 sbxbot sasusers 819 Apr 13 19:29


Create a CAS script

Option: SAS Studio V

In your environment, open SAS Studio V, log with your user and password.

Navigate to: intviya01/Home/devops/git-demo/Data-Management/scripts/


Create a new SAS program. Copy the SAS code below.

cas casauto;
caslib _all_ assign;
proc casutil incaslib="Public";
list files; list tables;
cas casauto terminate;

Paste it.

Save the program under intviya01/Home/devops/git-demo/Data-Management/scripts/ as .

Back to MobaXterm and the command line.


Option: MobaXterm

Browse to:

cd $HOME/devops/git-demo/Data-Management/scripts/


Create a new file (right click) named .

Copy the SAS code above.

Paste it.





git checkout

Create a new branch, named {your-user-branch}, for new work to go into:



Change {your-user-branch} in the statement below:

cd $HOME/devops/git-demo/
git checkout -b {your-user-branch}
[sbxbot@intviya01 scripts]$ git checkout -b sbxbot
Switched to a new branch 'sbxbot'


git add

Usage: git add [file]  

This command adds a file to the staging area.

git add .

. adds all changes to the staging area. Or,

git add -p

. adds only the file to the staging area.


git status

Usage: git status  
This command lists all the files that have to be committed.

git status
# On branch sbxbot
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#       new file:


Change after a commit

Edit the with SAS Studio or MobaXterm (whatever you used earlier). Add an Enter after casauto;

caslib _all_ assign;
proc casutil incaslib="Public";
list files; list tables;
cas casauto terminate;


git diff

Usage: git diff

This command shows the file differences which are not yet staged. Very useful to understand the changes.

git diff
diff --git a/Data-Management/scripts/ b/Data-Management/scripts/
index c0dc022..6752fad 100644
--- a/Data-Management/scripts/
+++ b/Data-Management/scripts/
@@ -1,4 +1,5 @@
 cas casauto;
 caslib _all_ assign;
 proc casutil incaslib=”Public”;
 list files; list tables;


git commit

Usage: git commit -m “[ Type in the commit message]”  

This command records or snapshots the file permanently in the version history.

git commit -m "Added new .sas program"
You committed without the change. To incorporate the change, do git add . or git add – p  for a specific change.
[sbxbot 76d01e3] Added new .sas program
 1 file changed, 6 insertions(+)
 create mode 100644 Data-Management/scripts/


git log

Usage: git log
This command lists the version history for the current branch.

git log
commit 76d01e3b0578ddfc4ca60bd8fd555b7e7c703603
Author: “sbxbot” <>
Date:   Fri Apr 10 08:44:49 2020 -0400
    Added new .sas program

Scroll with Enter until (END) then CTRL + Z.


git push

Usage: git push [variable name] master

This command sends the committed changes of the master branch to your remote repository.

{your-user-branch} is your branch you created in the git checkout command (GitHub user):


git push origin {your-user-branch}

For the sake of simplicity, we will use https as a method to connect (user and password). You could use ssh too, several other steps are required. For more info on how to set-up ssh for git, see Xavier’s video.

You might see:

Username for '': bteleuca
Password for '':
Counting objects: 8, done.
Delta compression using up to 10 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 606 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)

The remote branch {your-user} has been pushed remotely:


Navigate to{your-user}/git-demo/tree/{your-user-branch}/Data-Management/scripts



Fork a second repository

Let’s assume you want to push the changes in another repository:


From top right, press Fork. Sign-in if necessary.

The project becomes {your-user}/git-demo e.g. in my case.


git remote

Usage: git remote add [variable name] [Remote Server Link]  

This command is used to connect your local repository to the remote server.

Change the remote

cd $HOME/devops/git-demo/
git remote rename origin old-origin
git remote add origin
git remote -v
old-origin (fetch)
old-origin (push)
origin (fetch)
origin (push)

The new origin becomes the git-demo2 repository.


Push the changes to the new remote

git push origin {your-user-branch}
git push origin sbxbot

At this point you will see in the target repository{your-user}/git-demo 



git pull

Usage: git pull [Repository Link]  

This command fetches and merges changes from the remote server to your working directory.

Suppose another developer updated a program in the /scripts folder, and pushed it in the remote repository{your-user}/git-demo  . You need to update your local copy before you develop further.


git pull old-origin master
 * branch            master     -> FETCH_HEAD
Already up-to-date


No changes remotely, therefore you can proceed safely.


git branch

Lists all branches in the repository.

git branch -av
master                    bd0b252 Delete
* sbxbot                    b85200a Merge branch 'sbxbot' of into sbxbot
  remotes/old-origin/HEAD   -> old-origin/master
  remotes/old-origin/master bd0b252 Delete
  remotes/old-origin/sbxbot b85200a Merge branch 'sbxbot' of into sbxbot
  remotes/origin/sbxbot     b85200a Merge branch 'sbxbot' of into sbxbot



Setting up Git repository in SAS Studio 5.2 (excellent video by Xavier, SSH setup clearly explained).


We looked at the most common git commands you might need to write, if you are in a DevOps scenario involving SAS Viya. Next, you might want to read the DevOps Applied to SAS Viya 3.5 series:


Mark Thomas, Rob Collum, Stephen Foerster for their contributions.

Want to Learn More about Viya 3.5?

Thank you for your time reading this post. Please comment and share your experience with the git commands and help others.

Version history
Last update:
‎07-19-2021 02:24 AM
Updated by:



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started