Skip to content

Latest commit

 

History

History
119 lines (88 loc) · 4.38 KB

File metadata and controls

119 lines (88 loc) · 4.38 KB

git

Updating a repository from the command-line.

References

"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

Install git

Section 1.5 in the onlinen book has guidance on installingn command-line git. All of Chapter 1 in the online book is worth reading if you want background on git.

Tutorials

These tutorials describe advanced usage of git and github, which we'll use later in the course.

Cloning a repo

$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY

Reference:

Committing changes

After you make a change in to your local repository, you 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 (and lose everything since then!)

$ get reset --hard <tag/branch/commit id>

References:

Branches

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:

Update a repository

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

Pull requests

Creating a pull request -- github.com