Lessons in Linux

For example, if you are in the myscripts directory under your home directory on a Linux system, you could run the following commands to turn the myscripts directory into a Git repo (this will also create a hidden .git folder underneath the myscripts directory):

[jason.eckert@csc-studev01 ~]$ pwd /home/jason.eckert

[jason.eckert@csc-studev01 ~]$ cd myscripts/ [jason.eckert@csc-studev01 myscripts]$ pwd /home/jason.eckert/myscripts [jason.eckert@csc-studev01 myscripts]$ ls chownscript.sh filemaintain.sh newuserscript.sh seccheck.sh sysusage.sh [jason.eckert@csc-studev01 myscripts]$ git init Initialized empty Git repository in /home/jason.eckert/myscripts/.git/ [jason.eckert@csc-studev01 myscripts]$ git status On branch master

Initial commit

Untracked files: (use “git add ...” to include in what will be committed)

chownscript.sh filemaintain.sh newuserscript.sh

seccheck.sh sysusage.sh

nothing added to commit but untracked files present (use “git add” to track) [jason.eckert@csc-studev01 myscripts]$ _

Notice that the git status command above listed the files in the myscripts directory, but said that they were untracked – this is normal, because Git doesn’t assume you want everything version controlled. After creating a Git repo, you have to tell Git which files you want to version control by staging them with the git add command. Staging simply adds the files to an index that represents the files that Git can take a snapshot/commit of. git commit After the files have been staged, you can take snapshots of them using the git commit command. The following commands stage all the files in the myscripts folder using the * wildcard (because I’m lazy), shows that they are ready for committing and then creates a new commit with the description “My first commit”:

[jason.eckert@csc-studev01 myscripts]$ git add * [jason.eckert@csc-studev01 myscripts]$ git status On branch master

Initial commit

Changes to be committed: (use “git rm --cached ...” to unstage)

Made with FlippingBook Online document