The following git commands sets your name and email for commits.
git config --global user.name "Bruce Wayne"
git config --global user.email "[email protected]"
The following git command will intialize a new Git repository in the current directory
git intit
The following git command clones a remote repository to your local machine
git clone https://github.com/bwayne/repo.git
The following git command lets you see which files have changed and are either staged or unstaged
git status
The following git command stages files for commit
git add myfile.js
git add . #Adds everything
The following git command will commit files that are staged
git commit -m "Describe what was changed"
The following git command will push committed changes to the remote repository
git push origin main #Push to the main branch
The following git command will pull the latest changes from the main branch and update the local repository to match the changes
git pull origin main
The following git command will fetch the latest changes from the remote respository without merging them with your local branch
git fetch
Branching allows you to create a seperate workspace where you can work on project features or bug fixes without affecting the main project.
The following git command lists all branches
git branch
The following git command creates a new branch
git branch new-feature
The following git command allows you to switch to a branch
git checkout new-feature
The following git command will a branch into your current branch
git merge new-feature
The following git command will unstage a file
git restore --staged myFile.js
The following git command will discard changes to a file that has not been committed
git restore myFile.js
The following git command will undo your last commit
git reset --soft HEAD~1
The following git command allows you to view commit history
git log
The following git command allows you to view a compact visual graph of commits
git log --online --graph --all
The following git command allow you to view linked remote repos
git remote -v
The following allows you to add a remote repository
git remote add origin https://github.com/user/my-project.git
The following git command will push and set the upstream branch for tracking
git push -u origin main
The following git command removes untracked files
git clean -f
The following git command temporarily saves your work
git stash
The following git command allows you to reapply stashed work
git stash pop