-
Notifications
You must be signed in to change notification settings - Fork 2
How to make a commit
When you make changes, before you make a commit, check what branch you are on. If you're not sure what a branch is, look here: [What is a branch?].
git branch
When you run this command, you will get a return that looks something like this:
eyc3/setup_routes
eyc3/setup_schemas
eyc3/vercel_action_integration
* master
What this means is that I have 4 branches locally. And the *
next to master
means that I am on the master branch.
You should never commit to master, because that will affect the master code, and therefore make changes to wece.ece.illinois.edu. Additionally, there are permissions on Github.com that will prevent you from making commits to master, so you don't need to worry about accidentally committing to it.
If you are on the master branch, go to your own branch from the list of branches by running git checkout
. For example:
git checkout eyc3/setup_routes
If you have not created your own branch yet, follow the instructions at [How to create a new branch and first commit] instead of this guide.
Your terminal / command prompt should have a prefix that tells you what folder you are in. It looks something like this:
MGY442:~/git/wece-next-app eugeniachen$
or this:
C:\Users\eugeniachen\git\wece-next-app>
This is saying I am in the wece-next-app
folder.
Alternatively, you can run:
pwd
This will tell you what your current working directory is. That will return something like this:
/Users/eugeniachen/git/wece-next-app
If you get something that doesn't end in wece-next-app
, you are in the wrong directory.
If you are in wece-next-app/client
or wece-next-app/api
, you need to go to the previous folder to get back to wece-next-app
. Run this to get to the previous folder:
cd ../
If you are not in wece-next-app
at all, you can check where you are by running this:
ls
ls
stands for list and will show you all the files/folders in your current directory.
For example, it might return something like this:
html-css-workshop wece-next-app
htmlhint-test wece-static-site
Then to go to one of the directories that is listed, you use cd
, which means change directory. For example, to go to wece-next-app
from the listed folders:
cd wece-next-app
When you are on the correct branch, you should now check the status to see what changes you have made.
git status
If you have not made any changes, it should say there is nothing to commit. You will get a message with something like the following:
On branch eyc3/setup_routes
Your branch is up to date with 'origin/eyc3/setup_routes'.
nothing to commit, working tree clean
If you have made changes, you should see what files have been changed in red text. It will that these are Changes not staged for commit
. For example:
On branch eyc3/setup_routes
Your branch is up to date with 'origin/eyc3/setup_routes'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: api/routes/user.js
modified: client/pages/join.jsx
no changes added to commit (use "git add" and/or "git commit -a")
This says that I have modified two files: api/routes/user.js
and client/pages/join.jsx
.
First, make sure you see your modified files from running git status
. Then, you need to stage your changes for commit in order to commit to your branch. Staging just means adding a change to your commit.
To stage the change, run git add
. For example, to add the user.js
file, I need to add that file path:
git add api/routes/user.js
Make sure to replace api/routes/user.js
with the path to your file.
Now, run git status
again.
git status
Now it should return something like this:
On branch eyc3/setup_routes
Your branch is up to date with 'origin/eyc3/setup_routes'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: api/routes/user.js
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: client/pages/join.jsx
This is telling us we have added the file api/routes/user.js
. And it says this is a change to be committed.
It also tells us that the client/pages/join.jsx
file has not been staged yet. If you also want to add this file to your commit, make sure to run git add
for it as well.
If you want to stage all the modified files, you can use this shortcut:
git add .
The .
just means we are adding all the files.
Now, you can commit your changes to your branch. To commit, run this:
git commit -m "create file for new page"
-
git commit
means we are creating a commit to our branch -
-m
means we are adding a message - The text inside the quotes is the message for the commit. Add a short description of the changes you have made.
The next step is to push your commit to your branch on Github.com. Run:
git push
You should see a message that has something like this at the end:
To https://github.com/uiuc-wece/wece-next-app.git
53a7dcf..111fc14 eyc3/setup_routes -> eyc3/setup_routes
This means it has succeeded!
If it says something like Updates were rejected
, it means the push failed. In that case, follow the hints that are provided in the terminal / command prompt.
If you haven't created a pull request yet, follow the instructions here: [How to create a pull request].