For a comprehensive cheat sheet see github's one
In rough order of importance:
git clone https://special-url-you-paste-from-git-website.com/repo.git
git add filename
git add .
git status
git commit -m "Commit message goes here"
git push origin branch-name
git checkout -b new-branch-name
git checkout existing-branch-name
git pull origin branch-name
- Warning pull
also merges it the branch you're currently on. If you don't want to merge it, use git fetch
.
The Nuclear bail out ☢️
git clone
the whole thing again into a new folder and start from there :smile:
git diff
git diff --cached
cd <directory code is in>
git init
You can then git remote add origin https://special-url-you-paste-from-git-website.com/repo.git
to add the website as a remote.
And then git push origin master
to push it.
git mv file1 file2
Moving is a special operation in git. As well as add and remove.
You can either do a mv file1 file2
. But git will think you deleted file1 and created file2. So git status
will show two changes.
git mv
keeps the commit history neater.
Use these with caution.
git reset --soft HEAD~1
This leaves the changes already added but not yet committed.
To uncommit the past 3 commits is: git reset --soft HEAD~3
git reset --hard HEAD~1
git reset --hard origin/master
<- Goes to github of origin remote, finds master. And completely replaces the current branch you are in with those commits.