Guys I'm a first year computer science college student and new to programming and git. I am working on a school project teamed up with 3 other people.
I tried to go through some git tutorials but they are quite long and have too many details. I'd like to ask you guys about the minimal set of git command so that I can start working on the project.
Here is what I know so far about how to start working on the project
- to start the project I first need to
git clone
- Assuming now I'm on the master branch, I need to create a new branch base off of the master brach by
git checkout -b <newBranch>
- After some coding, I
git add .
and if it is ready to commit, Igit commit
then finallygit push
So here is my first question, assuming I continue to work on the same feature, i.e. I stay in the same branch, the next commit should be git commit —amend
or still git commit
? I understand that git commit —amend
lets you combine staged changes with the previous commit instead of creating an entirely new commit. So I am not sure if the two commits are about the implementation of the same feature, should I combine them or not?
And if someone in my team made some changes in the repo, I need to sync my local master with remote master, I did some research and I know there are probably two ways to go about doing it.
One approach is
git checkout master
to switch to the master branchgit pull
to get the latest codegit branch -b <newBranch>
to create a branch tracking the master to work with
Then the other approach is
git fetch
git checkout master
git reset —hard origin/master
git branch -b <newBranch>
So here is my second question, are these two approach correct and are they the same? So can you guys suggest some other approach for syncing my local master with remote master