Repository Basics
Create a new directory, cd
to it in your terminal, and perform the following command to create a new git repository:
git init project-name
To create a working copy of local repository
git clone /path/to/repository
To create a working copy of a remote server
git clone username@host:/path/to/repository
Git Staging, Commits, and Pushing
Stage files via source control:
To add all changes to the index, which is the "queue" where uncommitted changes sit
git add -A
# or
git add *
To check current status of your branch, commits, and staged files
git status
To commit your changes
git commit -m 'message'
To push your commits to the master branch
git push origin master
Branching
Create a new branch named "feature_x" and switch to it
git checkout -b feature_x
Switch back to master
git checkout master
Delete branch named “feature_x"
git branch -d feature_x
Push the branch to the remote repository so that others can access it
git push origin <branch>
Updates and Merging
Update your local repository to the newest commit
git pull
Merge another branch into your active branch (check via git status)
git merge <branch>
If conflicts arise, make manual changes and then re-merge with git add
git add <filename>
Preview differences before merging changes
git diff <source_branch> <target_branch>
Tagging and Logging
Study repository history
git log
Looks at most recent merge
git log -1
Setting a Project Up With Git (Locally)
- In your terminal, initialize a local repository
git init
If necessary, don’t forget to add a
.gitignore
file
- In Terminal, do:
git add *
- In Terminal, do:
git commit -m 'YOUR-COMMENT-HERE'
Setting a Git Repository and Committing to It
- Go to GitHub and create a new repository, calling it
REPOSITORY-NAME
- In Terminal, do:
echo "# REPOSITORY-NAME" >> README.md
- Write to your
README.md
file: click here for reference - In your terminal, run the following commands:
git add README.md
git commit -m “INITIAL COMMIT COMMENT"
git remote add origin https://github.com/GITHUB-USERNAME/REPOSITORY-NAME.git
git push -u origin master
Using SSH to Connect to a Repository
For an existing repository:
- Go to GitHub and hit
Clone or Download
and then selectUse SSH
and then copy the URLsh git@github.com:…
- In Terminal, do
sh git remote set-url origin git@github.com:…
- In Terminal, do
sh git remote -v
to check if the process was completed correctly.
Deploying to gh-pages
- In Terminal, do:
npm init
- In Terminal, do:
npm i gh-pages
to install the proper dependencies - Create a
.gitignore
file, and addnode_modules
to the file. - In packages.json file, replace the
“scripts”: {}
default with:
"scripts": {
"deploy": "gh-pages -d dist”
}
- In packages.json file, change (or add) the
homepage
section:
“homepage”: "https://your-GH-username.github.io/repository-name”
Example:
"homepage": "https://connoro7.github.io/my-project"
- Go to GitHub and create a new repository with the same name that you created in the previous step, “repository-name”
- In Terminal, do
sh git init
- In Terminal, do
sh git add .
to add all to staging - In Terminal, do
sh git commit -m ‘COMMENT’
- Go back to GitHub and copy the
sh git remote add origin git@github.com…
line - In Terminal, paste the
sh git remote add origin git@github.com…
line - In Terminal, do
sh gitpush -u origin master
- In Terminal, do
npm run deploy
Top comments (0)