GitHub Basics - KSU-ART/tutorial-site GitHub Wiki
(In general, you should use the internet to discover how to do specific things. This is just a simple guide for how to do most things correctly)
- What is github?
It is "the" website used to back-up and share code. It allows you to easily work on a single project from multiple computers and with other people. It also saves the history of a project and lets you 'undo' any change.
- What is a repository?
A repository -or repo- is a personalized website that you can upload your code to. You should usually make a separate repo for every large project that you start.
- go to github.com and sign in
- go to github.com/new
- name your repository
- write a description of your project
- click the checkbox for "initialize this repository with a README"
- add .gitignore for python
- add a liscense (MIT usually)
- go to the folder you want to download it to
- open powershell (windows) or the terminal (linux)
- use
cd
to go to the folder you want
-
git clone <https://github.com/username/reponame.git>
- (without the <>. <> just means change it to what you want.)
git status
git add <changed files>
-
git status
(the desired changes to upload should be green) -
git commit -m "<what changes you made>"
- you need to set your name and email for this to work
- save changes
git push
- On Windows:
- Download the install kit from https://git-for-windows.github.io/
- open powershell and run commands:
git config --global user.name "<my_github_name>"
git config --global user.email "<my_github_email>"
- On linux:
sudo apt install git
git config --global user.name "<my_github_name>"
git config --global user.email "<my_github_email>"
- Make sure you are OK with losing all offline changes you have made to the repo
-
git reset --hard origin/master
- If you want to reset a different branch, change
master
to the name of that branch
- If you want to reset a different branch, change
Branches are copies of the repository that are used for developing specific features. It allows different parts of a project to be developed without it disrupting the whole project. Branches are merged into the master branch once work on a specific feature is complete.
To checkout an existing branch, go to a repo directory and run this command
git checkout <branch name>
To create a new branch, run this command
git checkout -b <new branch name>
To see what branch you are on, run this command
git branch
To upload a new branch to GitHub, run this command from the new branch
git push
GitHub is a version control software. This means that it allows you to keep track of multiple versions of code and revert to previous versions in times of need. This allows you to undo any change by any contributor to a project.
To see the list of changes made to a project's source code, run
git log
This displays a bunch of hash numbers for every commit and information about who made the commit and when the commit was made. To reset to a specific commit:
git reset <the commit's hash number>
to undo changes made during a specific commit:
git revert <the commit's hash number>
Red stuff is untracked, green stuff is tracked.
git status
When you are satisfied with a change, begin track it with
git add <path/to/fileOrDirectory>
Then, run
git status
To check if your change is being tracked. Green files/directories are tracked, red code is untracked.
A commit contains a certain change, a message explaining the change, information about when the change occurred, and a unique ID. Please follow this style guide when commiting changes to this repository. It will make it easier for others to determine exactly what and why something was changed.
To commit all tracked changes, run
git commit
This will take you into a text editor. In the first line, make a header for the commit. If the change is complicated and requires more justification, go to a new line and elaborate there. After you are done, save the file.
A commit takes all tracked code and pushes that code into the local repository "head" (the place you are working right now). To upload your changes to GitHub, first make sure your local environment is up to date with the remote(online version):
git fetch
git rebase origin/<branch>
Then push your commit to the remote (online version) of the branch you are working on:
git push