git status, git add, git commit, git push
First, we need to create a new file for our repository. In this demonstration, I made an R script that contains a function that adds two numbers together. The file is saved to my repository.
I will also update my README file so that anyone who visits my repository knows that there is an R script that contains an "add_numbers" function.
Open your terminal and make sure you "change directories" (cd) so that you are working in your repository folder.
An Error on Changing Directories
I believe it's just as important to highlight errors as it is to show the correct way.
When I changed directories, I only changed to my "github_talk" folder and did not additionally go to my "demo" repository folder.
When I used a git command, my terminal gave me an error; "not a git repository."
Git will give you this error if you are trying to use git commands in a folder that is not a repository.
To fix this error, make sure you are in your repository folder.
For me, that just means changing directories one more time.
First, type "git status" into your terminal. git status shows all the files you have changed and gives recommendations on what commands you should use next. It is a great way to see the "status" of your files before you move on to doing any other commands.
The first line tells us what branch we are working on, which is the "master" branch. The following line tells us our repository is up to date (meaning our local and remote repositories match).
Our "README.md" file is under the section "changes not staged for commit," which means git has recognized this as a file in your repository. Git has noted that you have made changes to this file that are not on the remote repository nor have you "saved" or, in GitHub lingo, "committed" this version of the file.
Our "add_numbers.r" is under the section "Untracked files," meaning git has not been tracking changes on this file, usually because it is a new file that you've recently added to the repository.
Now we want to add our changes to our "commit." Our "commit," which we will do later, will contain all of the additional changes we want to make to our remote repository.
Before we commit, we have to first "add" our changes. We can add each individual file by typing "git add README.md" first then "git add add_numbers.r". However, I always appreciate a shortcut, and we will be typing "git add ." to add all the changes we've made to our commit.
Now both of our files are ready to be committed. To commit our files, we will type the following: git commit -m "adding files"
The "adding files" is a message associated with that commit, and each commit must have a message associated with it.
Note that when we enter git status, our files have disappeared, but we get an updated message that our branch is ahead of "origin/master" by 1 commit. This means we still have yet to update our remote repository with our changes.
Now, type "git push" to publish our changes to our remote repository.
There you have it! You've updated your remote repository. If you go back to GitHub website and see your repository, you will notice a couple of updates.
Note on Picture: Becaues I have registered my local computer under a different github account (and I didn't want to go through the process of connecting and disconnecting my demo and original accounts), I pushed my updated using my real account. You will see "beliciataylor" as a contributor and the one creating the commits. The process was the same. Your screen will solely have your account.
Our add_numbers.r file has been added and our README file has been updated.
Notice how our README file underneath our files has been updated with the sentence we added. This is a nice feature GitHub has to make the first thing a visitor of this repository sees is your README file describing the repository.
Last updated