Some notes about using git from the command-line.
"I really never wanted to do source control management at all and felt that it was just about the least interesting thing in the computing world (with the possible exception of databases ;^), and I hated all SCM’s with a passion." -- Linus Torvalds, creator of git
- Ref: git history
- git book, 2nd edition -- git-scm.com
- about git -- branching
You may have it already! So don't be in a rush to install it. Section 1.5 in the online book has guidance on installing command-line git. Chapter 1 is worth reading if you want background.
- 1.5 Installing git -- git-scm.com
- Note also: 1.4 Getting Started -- The Command Line
These tutorials describe advanced usage of git and github, which you may use later in the course.
- github starter course
- atlassian git tutorials -- atlassian.com
- Some very good tutorials
- Begginner guide
- Setting up a repository -- pretty good
- Collaborating -- later in the course
- github cli -- github.com
- This -- the github CLI -- is NOT the same as "git" (I don't use it)
After you make a change to your local repository, commit the changes and add a message:
$ git commit . -m "I made a small but super-important change to such and such."
To check the status of current repo
$ git status
To review the commit history
$ git log
To checkout a previous commit
$ get checkout <tag/branch/commit id>
To reset to a previous commit (because you'll lose everything since then!)
$ get reset --hard <tag/branch/commit id>
WARNING: Be super careful about using git reset --hard because it's destructive. Measure twice, cut once!!
References:
Branches allow you to develop outside the main branch. This is good for experimenting and collaborating.
$ git branch- list branches, including current branch
- default branch is usually "main"
- if you haven't created any branches, that'll be the only one
$ git branch demo- create the "demo" branch
$ git checkout demo- switch to the demo branch
- You need to specify the upstream for the branch before you can "push" or "pull"
- We're not going to be using the workflow for branches, at least not now.
- To merge a branch
$ git commit . -m "I made a such-and-such a change" $ git checkout main $ git merge demo - To delete a branch after merging
$ git branch -d branch
- To delete a branch without merging
$ git branch -D branch
References:
- git branch -- git-scm.com
- Git branching -- git-scm.com
- About branches
- Working with branches
You update the repository by "pushing to origin". This is okay if you're the only one working on the project.
$ git push origin main
If you've made a change, then you need first to commit
$ git commit . -m "I've made a such-and-such a change"
$ git push origin main
Creating a pull request -- github.com