Skip to content

Instantly share code, notes, and snippets.

@Subangkar
Last active May 16, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Subangkar/ede4edd8e9102472913f76a49e795083 to your computer and use it in GitHub Desktop.
Save Subangkar/ede4edd8e9102472913f76a49e795083 to your computer and use it in GitHub Desktop.
Git basic commands to use it from terminal
# init git repo
git init
# start git ignore
touch .gitignore
# clone repo
git clone <remote-repo-link> <local-repo-folder-name>
# add local repo to remote
git remote add origin <remote-repo-link>
# remove remote from repo
git remote rm origin
# rename remote
git remote rename origin github
# show remote & local branches
git branch -av
# show remotes
git remote
git remote -v
# stage all files
git add --all
# add & commit all changes
git commit -am"commit msg"
# add & amend commit
git commit --amend
# push current branch to remote_branch
git push origin remote-branch-name
# push a local branch to a remote branch
git push <remote> <local-branch-name>:<remote-branch-to-push-into>
# force push current branch to remote_branch
git push -f origin remote-branch-name
# force push a local branch to a remote branch
git push -f <remote i.e origin> <local-branch-name>:<remote-branch-to-push-into>
# Checkout to a remote branch
git checkout -b <new-local-branch> <remote i.e. origin>/<new-local-branch>
# fetch into a new branch
git fetch origin 'remote_branch':'local_branch_name'
# fetch all remote commits
git fetch origin
# reset current branch to specific commit
git reset --hard commit-id
git reset --soft commit-id
# point branch to a specific commit
git checkout <commit> #detach from branch
git branch -f <branch-name> HEAD #exactly as above
git checkout <branch-name> #optionally reattach to <branch>
# merge branch into current head
git merge <branch-name-to-merge>
# remove file from git but not from file system
git rm --cached file1.txt
git commit -m "remove file1.txt"
# remove remote branch
git push origin --delete remote-branch-name
# set a git global user name
git config --global user.name "user_name"
# set a git global attribute file
git config --global core.attributesfile ~/.gitattributes
# generate ssh key
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# copy public ssh key
cat ~/.ssh/id_rsa.pub | clip
# copy private ssh key
cat ~/.ssh/id_rsa | clip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment