Reputation: 4190
I am switching to git from other source control. The main issue I have now, is understanding branching. In other source control, if I would like to work on other branch I would clone it to another folder. In git from what I see is not the case. The work is done on the same folder for all branches or am I wrong?
Upvotes: 2
Views: 75
Reputation: 3031
Yes, your repo (with the entire history) is located in the main folder under .git/
. The other files in the main folder represent the currently checked out branch (working directory). With git branch
or git branch -a
you can see which branch is currently checked out. With git checkout <BRANCHNAME>
you can switch to another branch. This will replace the files in your working directory with the files from the given branch name.
More:
Better to commit more often than not.
Hard resets and force pushes are dangerous. With the latter, collaborators may have to clone again, because the repos must always have the same history (up to a certain point), otherwise you can't continue working.
If you are unsure, make a copy of your entire folder. Yes, actually Git is supposed to take over this role, but it has made my life a lot easier, at least as a beginner.
Best practice are commit messages with more than one word ;)
Upvotes: 1
Reputation: 7927
Branch is an abstract entity hidden deep in .git
folder. Essentially it is just a pointer to a commit with additional information about which commit is before it (sort of a linked list). At any given point of time, you have the folder of your project in a state of one of commits you've done + local yet uncommited changes you may have made.
When you jump to another branch, git
says it cannot switch while you have uncommited changes. When you revert uncommited changes, you can switch the branch, in which case git restores state defined by branch (i.e. commit) you're switching to.
Upvotes: 2