Git Quick Reference Guide
Git is a distributed version control software used for tracking change to any group of files. Git was originally developed in 2005 for use with Linux kernel development. The Git project is a member project of the Software Freedom Conservancy
Starting a Project
git clone
Copy and download a repository to local machine
Example 1. HTTPS clone
git clone https://{serverAdress.xyz[port]/path/to/project/repoName.git}
Example 2. SSH Clone
git clone ssh://{user@serverAddress.xyz[port]:/path/to/project/repoName.git}
git clone private GitHub repo with MFA enabled
First you will need to obtain a Personal Access Token (PTA) from your GitHub account. Settings > Developer Settings > Personal access token > Fine-grained tokens. Add the token to the repo url as shown below.
Example 3. HTTPS clone with PAT
git clone https://{PAT}@github.com/{userName or accountName}/{repoName.git}
Git Configuration
git config
Set User Email, Name and Password
Example 5. Set global user’s email
git config --global user.email "{emailAddress}"
Example 6. Set local repository user’s email
git config --local user.email "{emailAddress}"
Example 7. Set global user’s name
git config --global user.name "{usersName}"
Example 8. Set local repository user’s name
git config --local user.name "{usersName}"
Example 9. Set global user’s password
git config --global user.password"{password}"
Example 10. Set local repository user’s password
git config --local user.passowrd "{password}"
Example 11. Enable global credential storage
git config --global credential.helper store
|
Security Notice
credential.helper does store the credentials in plain text in the ~/.git-credentials file |
Send Updates To or From a Repository
Add, and Commit Changes
Branches, Commits, Tags, and Stashes Management
git branch
Example 22. List branches
git branch
Example 23. Create new branch. Does not move you to the new branch.
git branch {branchName}
Example 24. Delete a branch
git branch -d {branchName}
git stash
Example 25. Creates a new stash and reverts to the most resent commits
git stash
Example 26. Save a stash under a name
git stash save "{StashName}"
Example 27. List stashes
git stash list
Example 28. Restore the changes from the most recent stash
git stash pop
git checkout
Move Head to a specific commit, branch, or tag.
Example 30. Show UUIDs for commits
git log
Example 31. Move to a specific commit
git checkout {UUID}
Example 32. Check out a tags
git checkout {TagName}
Example 33. Move to a branch
git checkout {branchName}
Example 34. Create new branch and move to it.
git checkout -b {branchName}