# Git
# Git global setup
git config --global user.name "..."git config --global user.email [email protected]git config --global alias.co checkoutgit config --global core.editor "mvim -f"
# Basics
# git add
# git commit
- git add . => git commit -a
# git diff
# git stash
# .gitignore
# Undoing Changes
git clean
git revert
git reset
git reset HEAD~2Roll back to last 2 commitgit reset --hard HEADReturn to last commit state, delete previous changes**git initIntialize local gitgit add .Git add all filesgit statusgit loggit branchList all branchesgit branch <new branch>Create new branch with namegit checkout fileName.txtCheckout previous commit of fileName.txtgit checkout -fCheckout previous commit and overriding current changesgit checkout -b ...Create and switch new branch with name ...git commit -a -m "..."Commit all changes with messages ...git checkout masterCheckout to mastergit merge ...Merge branch to mastergit branch -d branchNameDelete branchName -d=delete commited changes only, -D=delete uncommitted changesgit push origin --delete remoteBranchNameDelete branch remotelygit fetch -pSynchronize branch list, -p "prune"
# Change only one file
git checkout -- hello.rbgit checkout HEAD hello.rbgit clean -d -x -nClean up uncommited files -d including directories, -x files ignored by git, -f dry run
Send changes to remote server
git push REMOTE NAME-OF-BRANCH
Exisiting folder
cd existing_folder git init git remote add origin https://gitlab.com/jycm/simple.git git add . git commit -m "Initial commit"
git remote add origin https://github.com/address.gitAdd remote git repository to local repo.git push -u origin masterPush local to remote repository using the -u flag/option (link up local/remote), "origin" name of remote repository and "master" name of branch.git remote show originShow remote git repo details:qto get out ofgit logAdd files to
.gitignore
# Push Branch to Remote
git push <remote> <branch>
// example push "feature" branch to "origin remote"
git push origin feature
//If upstream branch not created, need to run "-u" command with "git push".
git push -u origin feature
Push Branch to another Branch
git push <remote> <local_branch>:<remote_name>
//example
git push origin feature:develop
Before pushing branch, may need to merge remote branch to current local branch. Pull changes from remote branch to current local branch
$ git pull
$ git checkout feature
$ git merge origin/develop
$ git push origin feature:develop
Push branch to another Repository
$ git push <remote> <branch>
//See remotes in repo
$ git remote -v
// psuh branch to "custom" remote
$ git push custom feature
# SSH
# Check for exisiting SSH keys
$ ls -al ~/.ssh
# Lists files in exisiting .ssh directory, the default files one of following:
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
# Generate new SSH key
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
# Testing ssh connection
ssh -T [email protected] where [email protected] is the instance domain.