Using Git
caution
If you are not familiar with Git command line, do not pretend you know it.
Instead, install GitHub Desktop. It will make your life easier.
#
Setup your project- GitHub Desktop
- Git CLI
Install GitHub Desktop.
Click Clone or download
in the repository page and choose Open in Desktop
.
GitHub Desktop will auto open and guide you to clone the repository.
Install Git.
#
Pull latest changes from remoteTry keep your branch up-to-date with remote. Pull often.
- GitHub Desktop
- Git CLI
Click Pull origin
in the header.
Inside your working branch, run
#
Create a new branch- GitHub Desktop
- Git CLI
Command/Ctrl + Shift + N
or click Branch -> New Branch
in Menu.
Input the name of the new branch and GitHub Desktop will automatically go to the new branch.
#
Delete a branch- GitHub Desktop
- Git CLI
Command/Ctrl + Shift + D
or click Branch -> Delete
in Menu.
Click the Delete
button.
#
Review your changes locally- GitHub Desktop
- Git CLI
Just see what's changed directly within GitHub Desktop.
#
Select changes to commit- GitHub Desktop
- Git CLI
You can unselect the files you don't want to commit. Inside a file, you can deselect lines that you don't want to commit. (Only lines highlighted with blue on the left will be committed.)
The fill in the commit message, and click Commit to [your branch name]
.
If you only want to commit changes in a.js
, run
If you only want to commit changes in folder src
, run
If you want to commit all changes, run
#
Push to remote- GitHub Desktop
- Git CLI
After you commit, you should push your changes to remote, so that
- If you computer dies, changes will persist;
- Other team members will see your progress.
Depending on whether you have published your branch before, you will either see
or
After you clicked the button, you can see the progress.
If the branch does not exist on remote yet, Git will reject the push but give you some instructions like:
Run git push --set-upstream origin [your-branch-name]
as instructed.
master
branch changes#
Merge in - GitHub Desktop
- Git CLI
- Select History Tab
- Select
master
branch - Click the
merge
button - If there are merge conflicts, GitHub Desktop will prompt you to fix them.
Inside your working branch, run
, and fix any merge conflicts that arises.
#
Amend and force-pushdanger
Only do this if you are sure that you are the only one who will work on this branch.
Sometimes you want to maintain a clean commit history. For example, you don't want to have a series of commits like
You can avoid commits like Fix linter error again again
by amend your previous commit.
Run
to add all your unstaged changes to your commit.
If the commit is already pushed to remote, you need to force push.
#
Rebase and force-pushdanger
Only do this if you are sure that you are the only one who will work on this branch.
Merge commits sometimes turn a nice linear commit history into a messy tree. If you want a nice
linear history, you will need to rebase when you want to "merge" in the latest master
change.
- GitHub Desktop
- Git CLI
Command/Ctrl + Shift + E
or clickBranch -> Rebase Current Branch
in menu- Select
master
branch and clickrebase
- If there are merge conflicts, GitHub Desktop will prompt you to fix them.
Inside your working branch, run
, and fix any merge conflicts that arises.
If the commit is already pushed to remote, you need to force push.