Skip to content

Instantly share code, notes, and snippets.

@WebSofter
Last active May 10, 2021 07:48
Show Gist options
  • Save WebSofter/1f77a05089f06fa2e3343a599d3bba22 to your computer and use it in GitHub Desktop.
Save WebSofter/1f77a05089f06fa2e3343a599d3bba22 to your computer and use it in GitHub Desktop.
General commands working with GIT
Untracked -> Commited -> Modified -> Staged
* Basic commands
git init #Init new git reo
git status #Show current git status
git add <filename or .(all)> #Add git changes to index
git rm --cached <filename or .(all)> #Remove changes from index
git commit -m "My message note" #Commit with message
git branch #Show list branches of repo
git branch my_branch #Create new branch
git branch -D my_branch #Delete branch by name
git checkout my_branch #Change current branch
git checkout -b my_branch #Create and change current branch to new
git push --set-upstream origin test #Create remote branch and push
git merge my_branch #Merge master branch to children branch
git config --global user.name "David Amirkhanov" #Setting global name for You
git config --global user.email "mail.websofter@gmail.com" #Setting Your global email
git remote add origin https://github.com/WebSofter/advertiser.git #Add remote origin for local repo
git push -u origin master #Push local repo to remote master branch
git pull #Pull from remote repo
git push #Push to remote repo
git diff <hash> -- <filename> #Show differents in file by hash
git checkout <hash> -- <filename> #Resset commit by hash
* Advanced commands
git log #Show git logs
git commit -am "My message note" #Add and commit with nessage
git mv filename.py ./folder/filename2.py #Move or rename file
git rm removingfile.py #Remove file
git restore --staged removingfile.py #Restore file from index
git show <commit_hash> #Show specify commit info by her hash
git rebase my_branch #Move current branche to end another branch as start
git rebase --abort #Reset current rebase state to start state
git remote -v #Check for setting remote origin for local repo
git remote add origin git@github.com:WebSofter/lessnor.git #Set remote origin for local repo
git branch -m <oldname> <newname> #Rename local branch
git branch -m <newname> #Rename current local branch
git ls-files --deleted #List of deleted files
git reset -- myfile #Remove fro index
git checkout -- myfile #Restore deleted file
* SSH commands
ssh-keygen -t rsa -b 4096 -C "mail.websofter@gmail.com"
ls ~/.ssh/id_*
ssh-copy-id user@hostname
cat ~/.ssh/id_rsa.pub
ssh user@hostname
git remote set-url origin git@github.com:WebSofter/lessnor.git # Set local repo as SSH conected remote
ssh -Tv git@bitbucket.org #Confirm that network is permitting traffic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment