How to github
How To Github
This is a simple tutorial on how to use the key functions in git and github. Enyoj.
Install & update git
- Install;
brew install git
or use your preferred installer, like conda. - Check version or succesful installation;
git --version
- Update;
brew upgrade git
Link your computer to your GitHub account
- Create a ssh key Generate SSH key
- Add key to your github account Add SSH key to account
- Configurate by typing;
git config --global user.email "you@example.com"
Then you should be ready to roll.
Using git and GitHub
A Git project has three parts:
- A Working Directory: This is where you create, edit, delete and organise fileseither locally or on GitHub.
- A Staging Area: Where you’ll list the changes you make to the working directory and prepare for syncing and uploading.
- A Repository: Here is where Git stores the code and all those changes as different versions of the project.
The Git workflow consists of editing files in the working directory, adding files to the staging area, and saving changes to a Git repository.
Main Workflow
git pull
Download updates from remote github repo. Pull is a combined command of fetch and merge.git add .
List files and add them to uploading list. Specify a file to add or type.
to add all current changes to your staging area.git commit -m "message"
Commit specified files and changes. This step takes the updates from the staging area ans prepares an upload.git push
Upload files to remote repository. Merges you local repository to the main, if on main branch.
Check status of changes made to working directory; git status
See difference between working directory and last commit; git diff
Git Branches
If you are working on a large project with many people is involved, you might want to consider with branches. This protects different versions of the code.
- List existing branches;
git branch
- Create new branch “BRANCH”;
git branch BRANCH
- Switch to branch;
git checkout BRANCH
- git push origin BRANCH;
git push origin BRANCH