...
Git is a widely used software version control system that is used when people in groups develop software together. Most open source and proprietary sofware software systems are developed with some sort of version control system, with Git being the most popular.
At Rhodes, many professors use Git as a framework for distributed skeleton code and collecting programming assignments.
Info |
---|
The documentation here is a small glimpse into programming with Git – enough to get started. For a more detailed treatment, check out the free online book: https://git-scm.com/book/en/v2 |
Creating a Github Account
...
$ ssh-keygen -t rsa -b 4096
This will prompt you First, this command will ask you to enter a filename to store the key into. You can just press enter as the default file is the one we want (/home/<username>/.ssh/id_rsa
). Next, you will be prompted to make a passphrase. This is similar to a password, but should be longer and stronger. Make it something you won’t forget, but don’t worry – you won’t be typing it all the time like a normal password.
...
Here is an example of cloning an empty repository, creating a file, and pushing it back to GitHub:. Some whitespace has been added to make the example flow better and be more readable.
Code Block | ||
---|---|---|
| ||
$ git clone git@github.com:example/example.git Cloning into 'example'... warning: You appear to have cloned an empty repository. $ cd example $ ls $ echo "hello, world" > hello.txt $ ls hello.txt $ cat hello.txt hello, world $ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) hello.txt nothing added to commit but untracked files present (use "git add" to track) $ git add hello.txt $ git status On branch main No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: hello.txt $ git commit -m "this is a one line commit message" [main (root-commit) 0f31fb5] this is a one line commit message 1 file changed, 1 insertion(+) create mode 100644 hello.txt $ git status On branch main Your branch is based on 'origin/main', but the upstream is gone. (use "git branch --unset-upstream" to fixup) nothing to commit, working tree clean $ git push Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 238 bytes | 238.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:brianlarkinsexample/example.git * [new branch] main -> main $ |
Pulling in Updates from the GitHub Repository
The last stop on our (very) brief overview of Git is how to merge updates from the GitHub repository into your local version. You may need to do this if your professor updates the starter code and/or you are working with multiple developers and need to integrate their contributions into your local repository.
This operation is pretty simple:
$ git pull
Usually this will go off without a hitch, but it’s possible that you have local modifications to a portion of your code that someone else also modified. These are called merge conflicts and require special care to resolve (and is outside the scope of this tutorial).