Answer the question
In order to leave comments, you need to log in
What is the use case for git for a single developer?
Hello.
Finally, I want to understand git and understand how to use it correctly for working alone.
I have 1 project, computer and laptop on which this project is being developed. Accordingly, I need to have the current version of the project files on both machines.
Suppose I did something on my computer, left it unfinished, committed it to a local repository and pushed it to the server. The next day, working on a laptop, I received files from the server and continued to work. But with such a use case, there will be a bunch of commits on the server with unfinished functionality. In fact, the remote repository will become just a place to synchronize files.
How to do it differently and correctly? Create a "dev" branch, and commit everything unfinished to it? And only then in master?
Answer the question
In order to leave comments, you need to log in
You make a master branch, a dev branch and separate branches for separate features.
You make 2 sites - one project itself (main) - roll out master to it, the second site is a test site - roll out the dev branch to it. You develop the rest of the branches, merge them with dev, roll them out for testing, if everything is fine there, then merge dev with the master. Just when you sit down for a laptop, if there is a new master, do git pull and pull the new version
You work in a branch dev
, periodically pouring it into master
. For large tasks (not included in one commit), make separate branches from dev
.
Pouring dev
into master
, do it with a key --squash
like this:
git checkout master
git merge --squash dev
master
parallel with dev
which you need to resolve, and then you add and make one big commit:git add -A
git commit -m "Merged dev: %кратко (или нет) основные изменения%"
git push
merge
using the interactive rebase
:git checkout dev
git rebase -i master
dev
. Here you can blind the hated commits using the command squash
(and then you will be offered to edit the message) or fixup
(they won’t offer here) and then do it git push --force
(for one it’s not critical, it’s better to use in the crowd --force-with-lease
. git commit --amend
merge
you can already master
hang on the version label.
There is a very simple rule - right, the way it is easier.
You can even use master to synchronize all files, it's okay if there is an active development stage, you are the only developer, and the release is still very far away. And if you know how not to jump from one unfinished task to another.
As soon as you need to make releases, you can already get confused with master, staging, feature branches, etc., but only as needed.
PS. Since we are acting on the KISS principle, instead of a command line utility, it is better to use a convenient GUI, for example, on a Mac, this is Source Tree (in my opinion, the coolest program on my laptop).
It will also help to work with git more correctly - manually review and stage each changed file, and not through git add -A
.
If you do not fix bugs in the old version, while making a new version at the same time, then you do not need separate branches.
To get started, learn how to make clear commits. So that the changes (files included in the commit) and the purpose of these changes (the commit comment) match
It's simple, you work on a computer. Before you finish, commit and push everything. Sat down at the laptop doing pull.
If you are cutting a new feature, or something global, it is better to create a separate branch, and until everything is done on it. In fact, this is not necessary, since in any case all commits and history will be visible anyway, and it’s not realistic to mess up one, even if you do everything on the master.
The main thing is not to forget the simple rule, sat down at the pull computer before leaving the push computer.
understood nothing
Suppose I did something on my computer, left it unfinished, committed it to the local repository and pushed it to the serverwhy do you need to commit to a local repository?
But with such a use case, there will be a bunch of commits on the server with unfinished functionality. In fact, the remote repository will become just a place to synchronize files.Whoop!! And what do you need? So that every commit is a complete change? Break the task down into smaller subtasks.
For synchronization between two computers I use syncthing.
git and github (as remote master) is used for meaningful commits with completed improvements.
So I have a clean commit history, no rebases or other dubious activity to bring the history in order are not needed.
But that doesn't change the use of branches. A separate feature - a separate branch. Almost working - I merge in dev. After testing medju dev in master. I try not to commit directly to the master, except maybe some readme updates and other paraphernalia.
In master there is a code in which I am sure that it is working because the master is sometimes downloaded (the project does not require assembly because it is on pit and bash and is easily installed from source).
When the version is fully mature, I create a release (directly on github), and along the way, pour it into the PPA on launcpad (this has nothing to do with development itself - this is automatic delivery of updates to users).
I also use the develop branch for this, but lately I'm more and more inclined to think that this is not necessary.
It might be worth trying, in addition to the git, to use some Dropbox and push only completed meaningful things.
Commit everything as it is to a separate branch (dev or thematic task), upon completion of the task, rebase for the beauty of the story and merge into the master.
I use master as my main development branch, where I try to push mostly working and finished code. For the development process, I create separate topic branches, which I put in order with git rebase before merging with the master (well, periodically for long-lived branches).
I prepare the production code (releases) in a separate branch and merge the release branch with master and production.
Non-working code and all sorts of imperfections I commit only to thematic branches and add the prefix "WIP" (work-in-progress) to the description of the commit and sometimes I add information about what else I wanted to do, but did not have time to do.
As I understand it, this is predominantly a gitflow policy, with a touch of Gilab flow (when the development branch is master).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question