Version Control
Check this guide (opens in a new tab) to learn more about version control using Git.
Git
Git is a distributed version control system (DVCS) that tracks changes in any set of computer files, usually used for coordinating work among programmers who are collaboratively developing source code during software development. It was originally authored in 2005 for the development of the Linux kernel.1
Commands
A selection of porcelain Git commands with corresponding tutorials to get started:
git init
(opens in a new tab)git clone
(opens in a new tab)git config
(opens in a new tab)git fetch
(opens in a new tab)git pull
(opens in a new tab)git add
(opens in a new tab)git commit
(opens in a new tab)git push
(opens in a new tab)git status
(opens in a new tab)git diff
(opens in a new tab)git rebase
(opens in a new tab)git stash
(opens in a new tab)git branch
(opens in a new tab)git merge
(opens in a new tab)git remote
(opens in a new tab)git checkout
(opens in a new tab)git reset
(opens in a new tab)git revert
(opens in a new tab)git clean
(opens in a new tab)git rm
(opens in a new tab)git log
(opens in a new tab)git tag
(opens in a new tab)git blame
(opens in a new tab)git lfs
(opens in a new tab)
A cheat sheet of Git commands from Atlassian is available here (opens in a new tab).
Collaboration
Git
Install Git (opens in a new tab), if it is not available on your system:
sudo dnf install git
Configuration
Configure your global username and email address:
git config --global user.name "Jane Doe"
git config --global user.email "[email protected]"
Keys
Set up your SSH keys using this guide (opens in a new tab):
sudo dnf install pwgen xclip
pwgen -s 32 1 | tee >(xclip -sel c)
# mCiIVukNJukuZiApUUfeR7suQ2hvjZHL (passphrase)
ssh-keygen -t ed25519 -C "[email protected]"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Account
Create a GitHub (opens in a new tab) account, if you do not have one already, and sign up for the GitHub Student Developer Pack (opens in a new tab).
Authorization
Upload your public key to GitHub using this guide (opens in a new tab):
sudo dnf install gh
gh auth login
gh ssh-key add ~/.ssh/id_ed25519.pub --type authentication
gh ssh-key add ~/.ssh/id_ed25519.pub --type signing
Repository
Accept your GitHub Classroom (opens in a new tab) individual repository invitation and clone it locally:
git clone [email protected]:cmps405f24/individual-[username].git
Team
Accept your GitHub Classroom (opens in a new tab) team repository invitation and clone it locally:
git clone [email protected]:cmps405f24/team-teamname.git
Class
Clone the read-only class repository (opens in a new tab) locally:
git clone [email protected]:cmps405f24/labs.git
Fetching
Fetch the latest commits from the remote repository; this will not modify your local copy:
git fetch
Pulling
Enable pulling with fast-forward only, to avoid dealing with three-way merging:
git config --global pull.ff only
Pull the latest commits to apply them to your local repository and update your local copy:
git pull
Now, the local and remote repositories are synchronized.
Staging
Stage your changes to your local repository:
git add script.sh main.c
git add directory
git add .
You can create a .gitignore
configuration file in the root of your projects to ignore everything expect *.md
, *.sh
, *.c
, and *.java
source files:
*
!*/
!*.md
!*.sh
!*.c
!*.java
Signing
Setup signing commits with your SSH key using this guide (opens in a new tab):
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
Committing
Commit your staged changes to your local repository using a descriptive and concise summary:
git commit -m "Concise and descriptive summary of the changes"
All the modifications can be staged automatically and committed, if desired:
git commit -a -m "Concise and descriptive summary of the changes"
Pushing
Push your local commits to sync them with the remote repository:
git push
Now, the local and remote repositories are synchronized. This is how you will collaborate on and submit your projects.
You must push before deadlines as commit dates can be overridden using git commit --date="YYYY-MM-DD HH:MM:SS"
.
Conflicts
GitHub Desktop (opens in a new tab) and Visual Studio Code (opens in a new tab) can be used as well for a more visual and user-friendly Git interface, but it is preferable to use the command-line to practice working with the shell and have a better understanding and control of the commands and workflow.
Resources
- Getting Git right (opens in a new tab)
- Start your journey (opens in a new tab)
- An Introduction to Git (opens in a new tab)
- Generating a new SSH key and adding it to the ssh-agent (opens in a new tab)
- Adding a new SSH key to your GitHub account (opens in a new tab)
- Pro Git (opens in a new tab)