Creating, Staging, Committing, Merging, and Pushing Files
For the last element in this section, we're going to walkthrough a typical workflow you would follow when using version control. The basic steps are
- Pull - Move the latest revisions to your local computer
- Branch - Make a new version based on the main branch
- Edit - Make the changes needed to do the job
- Commit - Check those changes into the local version of your repository
- Push - Push those changes to the remote repository ( on Github.com in this case )
Once you've cloned the repo to your local repository, click on the branch name on the left hand side of the screen in Sourcetree to change to that branch. Click on Pull on the top bar to get any updates.
With the main branch chosen by clicking on the main on the left sidebar in Sourcetree, click on the branch icon on the top menu bar. Name the new branch week1. Once you click Create Branch, the name will show up on the left sidebar in bold to indicate that that branch is checked out.
Open your IDE. if you are using VSCode, go to Open Folder and choose the folder to where you cloned your repo locally.
In the folder titled practicegit there is a file named Assignment1.txt. Open it and answer the question however you choose.
Once you have answered the question to your satisfaction, return to Sourcetree. Make sure that your week1 branch is in bold in the left sidebar to indicate it is checked out. Click on File Status higher up on the left side and you will be presented with a list of files which have been changed. There should be only one. These files have been changed but the changes have not been checked into your local repository yet.
In the lower half of the center column you should see a section called "UNSTAGED FILES" and in it the Assignment1.txt file should be listed. Click on it.
You should see the contents of your file appear in the upper right. Back in the center column, click on "STAGE SELECTED" (On Mac: right click and choose Stage Files ). This will move Assignment1.txt from the unstaged area to the STAGED FILES area. This area is a list of all the files which are going to be put into your repo but are not there yet.
At the bottom of the screen you will see a text box with the button COMMIT underneath it. In the text area, type "Week 1 Assignment". It is customary to put a comment describing the work you did for each commit. Click Commit. This will put your file into the git repository in that folder. It is now in the version control system and managed by git. However, it has not been pushed to Github.com yet and therefore is only accssible to you.
After you have committed your files into your local repository, look at the Push button on the top tool ribbon in Sourcetree. There might be a 1 in a badge on it. This indicates that there is one commit which is in the local repo but not in the upstream repo on Github.com.
Click on Push.
if you run into security issues, move on to the next page to authenticate to Github.com. Pushing Changes to Github