MCS 275 Spring 2023
Emily Dumas
Reminders and announcements:
We pushed our git repo to GitHub.
We experimented with changes on GitHub and changes locally (without truly "collaborating").
We can mark other GitHub users as collaborators on a repo, allowing them to push to it.
(Private repos are invisible except to collaborators.)
Key consideration: Online repo can change with no action from us.
git pull
– get updatesgit log
– see what's changedgit add file1
git add file2
git commit
git push
– make changes available to othersgit push
Contact a remote repository and send it commits that are in our database but not theirs.
git pull
Contact a remote repository and get commits from its database that are not yet in ours.
The local and remote repos have a commit labeled HEAD, the "latest".
You can push only if the local HEAD derives from the remote HEAD.
You can always pull, but it may trigger a merge.
If a git push
fails, the solution is to:
git pull
– starts a merge, often completes automaticallygit push
– to send the unified updates to the remoteYou can have multiple lines of development underway at once, each with their own name and history. You can switch between them at will.
A repo starts with one branch called main
.
Each branch is just a pointer to its latest commit.
Branches can be local or shared.
git checkout -b my_branch_name
– Create new branchgit checkout my_branch_name
– Switch to existing branchgit checkout main
– Switch to the main branchgit branch -d my_branch_name
– Delete a branchgit commit
– commit staged stuff to active branchgit push origin my_branch_name
– push a branch to remote (default is to keep them local)Often projects keep main
clean, and do all work on changes in branches.
One branch per feature (or task) is common.
This way, features can be worked on in parallel.
Branches "end" in two ways:
To merge alpha
into beta
, ending alpha
:
git checkout beta
git merge alpha
The merge is a commit to beta
.
git blame
git blame FILE
shows commit that most recently changed each line of a file.
If you know where a problem is, this helps figure out how it got there.
git clone URL
– make a local copy of an existing repository.
Works with local repositories, too. Substitute directory for URL.
Like git init
, this is a rare event.