Git
version control system
Table of contents
Introduction
Git is a distributed version control system.
Setup
Using git bash
git init
git add .
git commit -m "init commit"
git remote add origin https://github.com/[username]/[reponame].git
git remote -v
git push origin master
git branch --set-upstream-to=origin/master
<!-- if unrelated history error -->
git pull origin master
git pull --allow-unrelated-histories
Git commands
git fetch --all -p; git pull; git status;
git merge origin/m
git push
git reset
git reset --hard // remove all local changes
git reset --hard origin/master // overwrites all local master changes with remote(origin) master
git branch
git branch //Show all local branches|
git branch -r // Show all remote branches|
git branch -a // Show all local as well as remote branches|
git remote
git remote
git stash
git stash save "message"
git stash list
git stash // tracked files
git stash -u // tracked and untracked files
git stash -a // tracked, untracked and ignored files
git tags
git push --tags
git fetch --tags
git fetch --tags --all --prune
git tag -d v0.1.2 // Delete tag locally
git tag -a <tag_name> -m "message" // Create tag locally
git push origin :v0.1.2 // Delete tag on origin
git push origin v0.1.2 // Create tag on origin
git tag pointing to old commit
# Delete the tag on any remote before you push
git push origin :refs/tags/<tagname>
# Replace the tag to reference the most recent commit
git tag -fa <tagname>
# Push the tag to the remote origin
git push origin master --tags
What’s Next
How to manage multiple GitHub accounts on a single machine with SSH keys
Deleting your git commit history without removing repo on Github
rm -rf .git
git init
git checkout -b init-branch
git add .
git commit -m "init repo"
git remote add origin github.com:<username>/<repo>.git
git push -u --force origin init-branch