{"id":27448431,"url":"https://github.com/nixin72/git-workshop","last_synced_at":"2026-05-08T00:39:16.187Z","repository":{"id":133984933,"uuid":"300409560","full_name":"nixin72/git-workshop","owner":"nixin72","description":"A workshop for teaching the basics of git","archived":false,"fork":false,"pushed_at":"2020-10-01T21:49:53.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T07:41:50.198Z","etag":null,"topics":["git","github","teaching","workshop"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nixin72.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-01T20:03:01.000Z","updated_at":"2022-02-02T05:08:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"daf56572-a011-4a73-a6c8-edd93b70d9f5","html_url":"https://github.com/nixin72/git-workshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nixin72/git-workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixin72%2Fgit-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixin72%2Fgit-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixin72%2Fgit-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixin72%2Fgit-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixin72","download_url":"https://codeload.github.com/nixin72/git-workshop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixin72%2Fgit-workshop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262343959,"owners_count":23296422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","github","teaching","workshop"],"created_at":"2025-04-15T07:25:52.623Z","updated_at":"2026-05-08T00:39:11.163Z","avatar_url":"https://github.com/nixin72.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Welcome \n\nIn this workshop we're going to be learning the basics of using git and GitHub.\n\n## What is git? \nGit is a distributed version control system that allows us to make changes to \na git repository locally, and then send our patches and changesets to others and \nautomatically manage the changes so that we can work together on projects.\n\n## What is GitHub? \nGitHub is a hosting service for git repositories. You can post your code on GitHub \nand using it to collaborate with people on projects.\n\n## Working with git solo\nWhile git is a great tool for working in teams, it's also a nice tool for working on\nprojects on your own. GitHub can store all your work so that you don't need to worry\nabout backups or anything, and it makes it super easy to share your work with others\nand show people what you've done. This section covers the basic commands you'll need\nto know to get started working on git on your own for school or any personal project\n\n### Cloning a Repository\nTo start, we're going to clone this repository. This means we're going to download \nall of the source code from the repo on GitHub to a local version of it. \n\nOpen up your command line and run\n```\n$ git clone https://github.com/nixin72/git-workshop.git\n```\n\nThen, we're going to move into that directory, and delete the `.git` directory\n\n```\n$ cd git-workshop\n$ rm -rf .git\n```\n\n**NOTE:** Normally we wouldn't do this when cloning a git repo, but we're going to this time \nso that you can start a new repo from scratch.\n\n### Initializing a repository\nTo get started with git, we need to initialize our project as a git repository.\nTo do this, we're going to run the command `git init`.\n\nWhat this will do, is it'll create a `.git` directory that contains a bunch of information\nabout the current directory. Don't worry about it for now. \n\nNow that our current directory is a git repo, how do we get our changes on to GitHub so that \nwe can work with others on it?\n\n### Staging local changes\nThe first thing we're going to do is stage our local changes. What this means is we're going\nto give git a list of files that we've made changes to, and tell git that we'd like to add\nthese changes to our staging. \n\nSo we can do\n```\n$ git add README.md\n```\nAnd that will add the README.md file to our staged changes. We use these staged changes to \nprepare all of the stuff that we eventually want to be commited. \n\n### Commiting staged changes. \nOnce we have our changes staged, then we can commit them. What this will do, is it will add\nto our git history all of the changes that we made in this set of staged files. Git will \nbe able to keep track of the history of all of our commits so that we can rollback our\nhistory at any point to any given commit. \n\nTo commit our changes, we do\n```\n$ git commit\n```\nThis will open up our default system text editor to write a commit message.\nIf you want to just write the message on the command line, we can do\n\n```\n$ git commit -m \"My commit message\"\n```\n\n### Getting the changes onto GitHub\nSo, before we can push the changes to GitHub, we first need to go onto GitHub and create a \nremote repository. So open up your browser and log into your GitHub account. In the top-right\nhand corner, there's a little plus. Click that, and the first option in the dropdown is to \ncreate a new repository. Give the repository a name, then click \"Create Repository\". For now, \ndon't click any of the checkboxes. \n\nOnce you've clicked the \"Create Repository\", GitHub will bring you to a page for a new empty\nrepository. We're going to use this empty repo to push our local changes into. \n\nCopy the name for the repository, it'll be the first line under the \"Quick Setup\" heading. \nIt should look something like https://github.com/yourusername/repo-name.git. Copy that.\n\nThen, back in your command line, run the command \n```\n$ git remote add origin https://github.com/yourusername/repo-name.git\n```\nNow, git will have the variable `origin` that points to that remote repository whenever we \nwant to push to our remote repo. So now that we have our remote added, we can run the \ncommand \n\n```\n$ git push origin main\n```\n\nAnd this will take all the local changes we've made, and push them to the main branch at \nthat remote repository that we have on GitHub.\n\n---\n\nWhen working on projects on your own, most of the time these are all you're going to need\nto work with git and GitHub. However, we use git to work in teams and work on big projects\ncollaboratively. To be able to do that effectively, we'll need to know a bit more. \n\n---\n\n## Collaborating with git and GitHub\nGit really shines when you're able to use it to collaborate with teammates, friends or \ncollegues on projects. In this section, we're going to cover the commands necessary to be able\nto use git for school.\n\n### Git branches\nWhen working in git, if everything is always pushed to main, then there's no guarantee \nthat what's in main is functional or has been tested or anything really. Using branches, \nwe can isolate our work so that when we make changes, we're not risking breaking anything \nthat's on the main branch.\n\nLet's create a new branch to isolate some changes that we're going to make.\n```\n$ git branch my-new-branch\n```\nThis will create a new branch in your local git repository so that you can use it to make \nall of your changes. However, creating a branch won't move you onto it. We can use \n\n```\n$ git checkout my-new-branch\n```\nTo start using that new branch that we just created. \nWe can alternatively do \n\n```\n$ git checkout -b my-new-branch\n```\nTo create a new branch and switch to it. Once you're on your new branch, create a file and \nadd some stuff to it. Doesn't matter what it is. \nThis is my new file:\n```\nThis is my new file. \nIt has 2 lines.\n```\n\nNow that we've added this new file, we want to add it to git.\n\n#### Checking our changes\nOne thing that's very helpful to do before we stage our changes is to see *what*\nwe've actually changed. Sometimes when you've been working for a while you can change \nmany different files in many different places. Often all these changes are unrelated, \nand so you'll want to add them to different commits. We can use the `git status` command\nto see all the files that we've changes.\n\n```\n$ git status\n```\nOnce we've seen all the files that are different, we can add them one by one, and give \nunique commit messages, or add multiple files under a single commit, so that we can \npreserve our git history to make it easier to rollback.\n\nOnce we know what we want to be adding to our staging area, we can run the same \n```\n$ git add filename.txt\n```\nas before, and then we can commit it.\n```\n$ git commit -m \"I added my test file.\"\n```\nThen we'll push it to our new branch:\n```\n$ git push -u origin my-new-branch\n```\nThis `-u` is a little different than before. This will make it so that as long as we're on \nthe branch `my-new-branch` we don't need to specify which branch we're pushing to. Without it, \nwe'd need to run `git push origin my-new-branch` every time.\n\n### Making Pull Requests on GitHub\nOpen up your browser to the git repository you created earlier, and click on the `branches`\nlink just above the file explorer. That will list all of the remote branches. Next to the \nbranch `my-new-branch`, there will be a button called `New pull request`. Click it, and it'll\nbring you to a new page for creating a pull request. In the text box, we can add a description \nfor what we want this pull request to be. I'm just going to say `Demoing creating PRs`.\n\nThen, click the button that says \"Create pull request\".\n\nThis will open up a pull request on the GitHub repository. This is a way for people to see what\nchanges someone wants to be adding to the main branch on GitHub with an easy way to compare the \ncode, review the code, approve or reject it, all sorts of things.\n\nFor now, we're going to merge the pull request with the main branch. Once we've merged that, \nwe'll see our main branch on GitHub updated to include the new file that we created. \n\nBack in your command line, run the command \n\n```\n$ git pull origin main\n```\nAnd all of the changes from the remote `main` branch will get pulled into your local `main`\nbranch and will automatically get merged together. Now, sometimes this merge process fails and \nwe get merge conflicts. We won't go over how to fix merge conflicts today unless we have time at\nthe end.\n\n### GitHub issues\nAnother important tool of GitHub is the issues. We can use issues to document our project \ndevelopment. Do things like create bug reports, track the addition of new features, ask \nquestions about a project, etc. When using open source software and you find a bug in it, \nit's very common to open up the issues for it's GitHub repository and see if other people have\nnoticed the same bug and how they fixed it. Or if no one has encountered it, then you can \nsubmit bug reports through here. It's very common to use these in projects as a way to \ncommunicate and collaborate.\n\n### Gitignore\nA lot of the time, you're going to want git to ignore certain files. Let's create a new Java class\ncall Example.java.\n\n```java\nclass Example {\n\tpublic static void main(String[] args) {\n        System.out.println(\"Hello world\");\n\t}\n}\n```\nIf we want to run this file, then we go into the command line and do `javac Example.java` to\ncompile it. Then to run it, we do `java Example`. If we look at the contents of our \ndirectory now, we have an `Example.class` file. This is a generated file, and not one that's \nuseful to people looking at the source code for our project. So what we want is for our `.class`\nfiles to never be added to git. To do this, we can create a special file `.gitignore`.\n\nThis is what it'll look like:\n```\n*.class\n```\nWhat this does is it tells Git that whenever it sees a `.class` file, it simply ignores it. So \nwe won't be uploading these files to GitHub at all.\n\nOther things we'd generally put in a gitignore file are things like libraries. If we had a \nJavaScript project, then we'd add our `node_modules` directory to our gitignore. We can also\nuse our gitignore to not commit files that have potentitally sensitive information, like \nenvironment variables with information for a database.\n\n## Conclusion\nI hope you've learned a lot about how to use git for your team projects! If you learned from\nthe workshop, let me know on Discord. If not, write an issue on the GitHub repo for this and\nlet me know what I can improve. \n\n## Appendix\nHere's all the commands that we learned to use in this tutorial:\n\n### git clone\n#### Example\n```\n$ git clone https://github.com/username/repo-name.git\n```\n#### Description\nWill clone a remote git repository to a local directory\n\n---\n\n### git init\n#### Example\n```\n$ git init\n```\n#### Description\nWill initialize the current directory as a new git repo. If it's already a git repo, it'll fail.\n\n---\n\n### git add\n#### Example\n```\n$ git add filename.txt\n$ git add -p filename.txt\n```\n#### Description\nWill stage all the changes in that file to be commited.\nWith the `-p` flag supplied, you can pick only the changes you want to be commited.\n\n---\n\n### git commit\n#### Example\n```\n$ git commit -m \"my commit message\"\n```\n#### Description\nWill add all the changes staged to a \"commit\" so that we can use that as kind of a checkpoint \nor rollback point in our git history.\n\n---\n\n### git push\n#### Example\n```\n$ git push -u origin main\n```\n#### Description\nWill push all of our commited changes on the current branch to the remote branch.\n\n---\n\n### git pull\n#### Example\n```\n$ git pull origin main\n```\n#### Description\nWill pull all of the changes in the remote repository into our local repository on the current\nbranch. If there's merge errors, you'll need to fix them.\n\n---\n\n### git fetch\n#### Example\n```\n$ git fetch origin\n```\n#### Description\nWill allow you to fetch all the objects on the remote branch and bring them into your local.\n\n---\n\n### git status\n#### Example\n```\n$ git status\n```\n#### Description\nWill show you all of the changes that have been made locally up to this point that haven't been\ncommited. Will show you all files created/modified/deleted, staged changes, etc.\n\n---\n\n### git diff\n#### Example\n```\n$ git diff filename.txt\n```\n#### Description\nWill show you all the differences in `filename.txt` between the current local changes and what \nthe file looked like in the most recent commit.\n\n---\n\n### git checkout\n#### Example\n```\n$ git checkout main\n$ git checkout -b my-new-branch-name\n```\n#### Description\nWill checkout a branch and change all of your local files to the most recent commit on that branch.\nIf the -b flag is supplied, it'll create the new branch will all your current changes.\n\n---\n\n### git branch\n#### Example\n```\n$ git branch -l\n$ git branch -d branch-name\n```\n#### Description\nWill allow you to list all branches or delete a specified branch\n\n---\n\n### git stash\n#### Example\n```\n$ git stash\n$ git stash pop\n$ git stash clear\n```\n#### Description\nAllows you to stash changes quickly if you want to change branches or check something out \nwithout adding those changes to a commit. \nAdding the `pop` subcommand will pop all of the changes out of the stash and apply them\nagainst your current files. \nAdding the `clear` subcommand will clear the stash of all the changes that have been added\nto it.\n\n---\n\n### git remote\n#### Example\n```\n$ git remote add origin https://github.com/username/repo-name.git\n$ git remote remove origin\n```\n#### Description\nAdds or removes remote repositories that you can use to collaborate with people. \nCan have multiple remote repositories so you can do things like push to either GitHub or\nHeroku.\n\n---\n\n### git reset\n#### Example\n```\n$ git reset HEAD~1\n```\n#### Description\nAllows you to undo things that you messed up. The example above will undo the most \nrecent commit if you did something you didn't want to do.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixin72%2Fgit-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixin72%2Fgit-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixin72%2Fgit-workshop/lists"}