git config --global core.editor "code --wait --new-window"
# create directory and files
mkdir ~/bootcamp/VSCode/foldername
cd ~/bootcamp/VSCode/foldername
mkdir my-app
cd my-app
touch index.html style.css
git init #add git tracker
# git add <path>/.
git add . #. means everything in current path
git add index.html # add individual files
git add style.css
git status # check update to staging area
git commit -m 'commit msg' #commit to local repository
git branch -M main #setup a branch
git remote add origin git@.... #connect remote repo: git remote add <name> <url>
git remote -v # check the connection
git push -u origin main #git push -u command
git push -u <remote> <branch name>
git push -u origin
because this pushes the current branch to a matching branch of the same nameTrack a different branch than the one you just set up
git branch -u <remote/branch name>
git branch -vv
for those who want to pull changes from the remote but only apply changes for one file
“the tip of your current branch is behind its remote counterpart” means that there have been changes on the remote branch that you don’t have locally.
If you created a README.md
file when creating the remote repo, this will inevitably happen. To fix this, you need to pull and push again
git pull origin main
-> git push --set-upstream origin main
git push --set-upstream <remote-name> <branch-name>
: sets up upstream branch (creates a new branch in remote repository and sets it up as the main branch for git push)git push -u origin +main
: force pushes this specific branchgit push --force
When you have divergent branches and need to reconcile them
git config pull.rebase false
to merge git pull origin main --allow-unrelated-histories
Here are many different ways of fixing this error, depending on your needs (warning: TLDR..)
git reset HEAD^
: cancels the most recent commit (used only when you didn't push it to the remote directory)git reset --soft HEAD^
: you will not lose the uncommitted changes you may havegit reset --hard HEAD^
: discards all changes in the working dirgit log --oneline
: shows all your commits and commit ids neatlygit reset <commitid>
: returns it to that specific commit reset
vs revert
Unlike the git reset command, the git revert command creates a new commit for the reverted changes. The commit where we reverted from will not be deleted. (ref)
You should use git reset when working on a local repository with changes yet to be pushed remotely. This is because running this command after pulling changes from the remote repo will alter the commit history of the project, leading to merge conflicts for everyone working on the project.
.
git reset is a good option when you realize that the changes being made to a particular local branch should be somewhere else. You can reset and move to the desired branch without losing your file changes.
.
git revert is a good option for reverting changes pushed to a remote repository. Since this command creates a new commit, you can safely get rid of your mistakes without rearranging the commit history for everyone else.
If you get stuck after writing git push --help
for instance, exit by typing q or z (Ctrl+C won't work!)
git clone
git clone <url> <dir>
- links it directly