Version Control
- Almost all “real” projects use some kind of version control
- Essential for team projects, but also very useful for individual projects
- Some well-known version control systems are CVS, Subversion, Mercurial, and Git.
- We’ll use Git and GitHub!
What are the functions of Version Control?
Version control (or revision control, or source control) is all about managing multiple versions of documents, programs, web sites, etc.
- A way to manage files and directories
- Track changes over time
- Recall previous versions
Why Version Control?1
- For working by yourself:
- Gives you a “time machine” for going back to earlier versions
- Gives you great support for different versions (standalone, web app, etc.) of the same basic project
- For working with others:
- Greatly simplifies concurrent work, merging changes
- For getting an internship or job:
- Most companies use some kind of version control
Download and Install Git (Optional for E 115)
Note: You can just upload files to GitHub directly through the web browser. Using the GitBash or command line is not required for E 115. However, using Git/Git Bash may make things much quicker once you get it set up!
- Standard one: http://git-scm.com/downloads
- You can use any text editor to edit your actual files, as is allowed in E 115.
- VS Code is allowed and can be convenient since it integrates into GitHub directly: https://code.visualstudio.com/docs/sourcecontrol/github
- Reference book: https://git-scm.com/book/en/v2
Introduce yourself to Git (Optional for E 115)
Once you’ve installed Git, you can use it through GitBash on Windows. It looks basically like the terminal (it functions pretty similarly to one, but doesn’t have quite everything working!). You can use the Terminal on a Mac/Linux machine
![](https://e115.engr.ncsu.edu/wp-content/uploads/sites/32/2024/07/image-35.png)
![](https://e115.engr.ncsu.edu/wp-content/uploads/sites/32/2024/07/image-36-1024x595.png)
![](https://e115.engr.ncsu.edu/wp-content/uploads/sites/32/2024/07/image-37.png)
Using your Repositories
Once you’ve set up an account at github.ncsu.edu, and have created the webpages
repository as described in GitHub account preparation, you can clone the repository.
- Get the files from your repository before starting.
- Make a local repository as a clone of main
git clone <blah>
(e.g.,git clone https://github.ncsu.edu/unityID/webpages.git
)- If you are having trouble, clone with
ssh
instead. But you may need to set up an SSH key. Follow these directions. - See all the contents of the folder
ls -a
to see the .git folder.
- Make a local repository as a clone of main
- Make changes
- See what changed
- git diff
- Stage changes
- git add –all (or particular files)
- git diff –cached
- Still only in your repository
- See what changed
Updating the Repository
- Put changes back up into repository
- Commit your staged changes in your repository
git commit -m "the reason for the change"
- Update the respository:
git push
- Commit your staged changes in your repository
- At this point, you should be able to see the changes in the browser and your files should match what you did locally.
Typical Workflow
git pull
- Get changes from a remote repository and merge them into your own repository
- This is only after you’ve cloned the directory the first time.
git status
- See what Git thinks is going on
- Use this frequently!
- Work on your files
git add –-all
(or just changes)git commit –m “What I did”
git push
- Much of the information on this page taken from CSC 116/CSC 216 resources. See powerpoint and webpage. Also powerpoint from University of Pennsylvania, edited. ↩︎