Initialise repo per the following link:
Publishing a new repo to GitHub from VS Code
- Create your new repository on GitHub. Do not add README, license or gitignore for now. Note the “remote repository URL”, which you will need in step 7 instead of URL.
- Open terminal
- Initialize a new Git repository:
git init
- Stage all your files before first commit:
git add .
- Commit the files:
git commit -m “Project started”
- Add remote repository:
git remote add origin {**URL**}
- Verify the remote repository:
git remote -v
- Push the first changes:
git push -u origin master
Action (8) basically says push to origin (remote repo) the diff from master (local repo).
- run Add, Commit, Push
- Remove cache from index (staging area):
git rm -r --cached .
- run Add, Commit, Push
Visit learngitbranching.js.org to learn how to git
- View reflog and history log, such as:
git log -5
andgit reflog -5
- Branches are essentially pointers to a specific commit, and can be created by:
git checkout -b "branchName"
or doing both the following:git branch "branchName"
,git checkout branchName
- Merging branches to master: merge commits and changes onto target branch, preserves history, better merge conflicts, easy to undo, can be messy (graphically):
git checkout master
,git merge branchName
- Rebasing branches to master: moves the commits and changes onto the target branch, a clean history, readable graph, harder to undo: in one command -
git rebase <CommitTo> <CommitFrom>
, or in two commands -git checkout <CommitFrom>
,git rebase <CommitTo>
- View the diff between branches:
git diff <<branch1>> <<branch2>>
- Graphically depict branch history with:
git show-branch -a
- HEAD represents the commit that git is working off, which is moved using the
git checkout <<pointer>>
command. To work off a specific commit (like a branch name commit pointer):git checkout <<commit_tag>>
- We can use the git branch pointer using
~n
to move n number commits upstream:git checkout HEAD~4
,git checkout master~3
,git checkout branchName~1
etc... - To force-move a pointer to a different commit:
git branch -f <<branchName>> <<pointer>>
, ie:git branch -f master HEAD~3
will force the master commit pointer upstream 3 levels relative to HEAD - A reset on a branch will work locally to move upstream of the commit we want removed:
git reset HEAD~1
. However, these changes are not pushed / shared with remote streams. - A revert on a branch will work remotely to move upstream of the commit we want removed, which it does by creating a new commit that completely reverses all preceding changes, thus, preserving history:
git revert HEAD
- We can cherry-pick to apply the selected commits to the currently checked-out branch:
git cherry-pick <Commit1> <Commit2> <...>
- We can also do some crazy shit by using interactive rebase to pick and squash and do other stuff:
git rebase -i <Commit1>
- Using tag we can create a permanent pointer to a commit, like a version release:
git tag AlphaVer <Commit1>
- We can determine where we are relative to tags by using:
git describe --tags <CommitName>
; output might be like:alphaDemo-4-g2e087f6
(-<# Commits upstream>-g)