-
Notifications
You must be signed in to change notification settings - Fork 296
Cheatsheet — Git & GitHub
Note: The tips below are tested under MS Windows.
-
Using HTTPS
With the HTTPS connection you will be prompted for your GutHub credentials when you clone, pull and push.
git clone https://github.com/telerik/ajax-docs.git
-
Using SSH
As for SSH, you should create an SSH key and add it to your GitHub account. More detail are available in this GitHub article—Generating SSH keys.
git clone [email protected]:telerik/ajax-docs.git
Information about that is available in this GitHub article—Generating SSH keys.
If there are complication head to the GitHub troubleshooting article on the matter—Error: Permission denied (publickey).
However, you can follow this steps to generate an SSH key:
-
Generate a file with your ssh key (passphrase is optional, although, recommended):
ssh-keygen -t rsa -C "[email protected]"
-
Add your new key to the ssh-agent:
-
Start ssh agent:
ssh-agent -s
or
eval "ssh-agent -s"
or
eval "$(ssh-agent)"
Tip: On my end, the
eval "ssh-agent -s"
andeval "$(ssh-agent)"
always do the job. -
Add the key to the ssh agent:
The file generated is available in the root folder, where GitBash has been started. Therefore, you need to use this file.
Note: The generated files are two -
[FileName]
and[FileName].pub
.ssh-add [FileName]
or
eval "ssh-add [FileName]"
-
-
Add your ssh key to your GitHUb account:
-
Remember the generated
[FileName].pub
file? Use the following command to copy the ssh key to your clipboard:clip < [FileName].pub
-
Head to your GirHub account;
-
Go to settings
;
-
Go to SSH Keys section;
-
Press the Add SSH key button—
-
A form will appear below, type a title and paste the key in the textarea below:
-
Add the key by using the green Add key button below.
-
-
Test the connection
ssh -T [email protected]
Staging is used to prepare a commit
or a stash
.
-
Staging all changes:
git add -A
or
git add --a
-
Staging a file:
git add filename.ext
Tip: With
Tab
key GitBash will list all files and folders available for staging. -
Staging an entire folder (and all file within):
git add controls/ajax/
Now, you can either commit or stash the staged files.
When adding a new commit—new pointer is added in the HEAD of the local repository.
git commit -m "description"
Stashing is useful for preserving changes made locally. By using stash, changes are not added neither to a commit, nor to the remote, but they can be restored.
-
Saving files into the
stash
:git stash
-
Seeing the available stash item:
git stash list
-
Showing files in stash
git stash show
or
git stash show stash@{0}
-
Getting the last saved stash:
git stash pop
or
git stash apply
-
Getting files from a certain stash item:
git stash apply stash@{0}
Pulling from a remote without a --rebase
procedure may cause a branch to appear in the history. That happens because the default pull
command triggers a merge
procedure. See the figures below.
Important: If there are changes that have not been staged, committed or stashed, Git will not let you to
pull
. To resolve that you can either commit the changes or stash them.
git pull origin master
git pull --rebase origin master
Pulling from a remote may lead to a conflict, when a file changed on your end has been committed by someone else before your push
.
Due to that, you are forced to resolve the conflict. When that happens, the re-base is paused. This is indicated in Git Bash—.
Start a resolve conflict procedure to merge changes, and eventually commit the changes. After that, you should continue the re-base procedure:
git rebase --continue
- Home
- Getting Started
- Deploying Documentation on IIS
- Git and GitHub Workflow
- Handling Redirects (link to the docs-seed wiki)
- Markdown Syntax (link to the docs-seed wiki)
- Markdown Nesting (link to the docs-seed wiki)
- Using Templates (link to the docs-seed wiki)
- Using Git and Git Bash
- Faster Jekyll Build via generate_exclude.rb Script
- Using Helper Tools
- Troubleshooting
- Use VS Diff tool with Git and SourceTree