Agenda
- General Concept
- Caveats
- how to clone
- how to branch
- how to commit
- how to update
- how to maintain
- Last Words
- References
1. General Concept
Basically, you'll get two branches at work: master and develop.
- The master branch is designed for production. The maintainers of your team project handle this branch to publish.
- The develop branch is designed for development. The developers of your team project stretch their own branches per feature and then merge the feature branches to the develop branch. The feature branches, of course, must be tested in advance of merging to the develop branch.
2. Caveats
You need to know the difference between "origin develop", "origin/develop", and "develop".
- "origin develop" is a remote branch on sites such as GitHub, gitlab, etc. Thus, we use like:
git fetch origin develop
git push origin develop
- On the other hand, "origin/develop" is a downloaded branch from a remote server such as gitHub, gitlab, etc. This means a downloaded branch could be out of date so that you must update the downloaded branch regularly. i.e. whenever you start coding in the morning or pushing your codes. Thus, we use like:
git merge origin/develop
git rebase origin/develop
- "develop" is a local branch you can modify. Thus, we use like:
git checkout develop
git diff develop your-new-feature
3. How to clone
Before you start developing, you need to clone your team project so that your teammates can work with the same project maintained by the same git.
git clone https://github.com/<username>/<project.git>
and then, go to the develop branch:
git checkout develop
4. How to branch
git checkout -b your-new-feature
5. How to commit
Let's add all changed files except for declared files in .gitignore.
git add .
git status
git commit -m "message here."
6. How to update
You need to update your downloaded branch before pushing your changes.
git fetch
git rebase origin/develop
And then, go to the develop branch, update your local develop branch ,and push your changes to the remote git repository.
git checkout develop
git merge origin/develop
git merge your-new-feature --no-ff
git push origin develop
7. How to maintain
You can track git commits:
git log --all --oneline --graph
Or, you can track git commits of a specific file:
git log -p ./path/to/file
You can figure out what changes to be committed:
git status
You can figure out differences by two options:
git diff
git diff --staged
8. Last words
This post could be a very unkind one since I skipped describing all details of git commands but focused on how to use git commands in a chronological order. However, by doing so, you can figure out the whole picture of how to use git at work.
I will appreciate that all comments point out something wrong on my post :) Thanks.
Top comments (0)