Below are basics for building a repository locally, pushing it to GitHub, and maintaining commits back and forth.
Create local git repository
1. Go to project directory.
2. Create git repository:
git init
3. Add files to repository:
git add .
# Alternatively, add files individually or with wildcards.
# To unstage a file, use 'git reset HEAD <filename>'
# Verify what you're about to commit:
git status
# Commit:
git commit
Add local git repository to remote
Put a local project onto GitHub (as opposed to a clone from GitHub).
1. Create repository on GitHub, without README, license or .gitignore files (yet)
2. Copy GitHub’s repository HTTPS URL
3. On terminal, add GitHub’s URL as ‘remote repository’
git remote add origin <remote repository URL>
git remote -v # Verifies new remote URL
5. Push changes from local to GitHub
git push -u origin master
6. Now add README, LICENSE, and .gitignore.
If adding these files on GitHub, remember to pull them back to local:
git pull origin master
For more, go to GitHub.come help page.
Clone GitHub repository to local directory
1. On GitHub, copy repo’s URL (click ‘Clone’).
2. On terminal, in directory you want to clone the repo’s directory, initiate the clone.
Note: the resulting repository directory name will be the repository’s name.
git clone <repo URL>
https://help.github.com/en/articles/cloning-a-repository
Push local to GitHub
git status
git add <file_name|directory_name>
git commit
git push origin master
Pull GitHub to local
git pull origin master
Leave a Reply