I'm about to start a team project for a class with some people that already know how to use Git... I've never used it before and I'm struggling to understand the concepts behind how the whole process works.
Say someone on the team uploads some boilerplate code onto the repository. I'd want to fork
it? And then work on it on my own and eventually push
to the shared repository? What happens if two people work on the same file and there are some differences, how does that get resolved? And where does pull
/ fetch
come in?
Sorry if my question isn't so clearcut... I just want to make sure I get the whole concept of how I'm suppsoed to use Git. Tutorials on GitHub and google queries have not been so helpful in giving me a good idea of how I'd want to use Git for a team project setting. Thanks.
There isn't a git fork
command, maybe you'd want to git clone
? For the rest of this answer, I'll assume that you meant git clone
as that's the command that pulls down a local copy of a repo.
What will generally happen is that someone will create a git repo on a server somewhere (either manually using git init --bare
on a server somewhere or using github to manage it for you) that you'll all use as a central server. This is the remote repo and is called origin by default. If for some reason you lose the original repo you cloned from, you can always just copy up the /path/to/local/directory somewhere and then have everyone else clone from that. Your coworkers may have done this already, you'll have to ask them.
Once the remote repo has been set up, each developer can clone it. To clone a repo, create an empty directory somewhere sensible, install git and then run git clone protocol://user@urltorepo.com /path/to/local/directory/
to pull a local copy of the repo down and stick it in /path/to/local/directory. After doing this, you will have a totally separate repo that mirrors the state of the repo at the time they cloned. You would then git commit
changes you make, git push
them up to the remote and then other people can git pull
your changes down.
Once you've cloned, there's no hard and fast rule about how exactly you use git, as git is more of a set of tools and not something that dictates a certain workflow, so ask your coworkers how they use git. Most of the time however, every dev will pull the latest changes from the remote with git pull
, make changes (often in a separate local branch), git commit
them and then push those changes up using git push
.
Each dev can make local branches using git branch foo
. This is fantansic as it allows you to keep master and your code separate until you explicitly want to merge them together. To create a branch:
git checkout master
git checkout -b foo #This will create the foo branch and then change to it
# Do some work
git add .
git commit #This commits the changes you have made to foo
And to deploy a branch:
git checkout master
git pull #Make sure that you are up to date
git merge foo
# Fix merge conflicts and commit if merge says that you have conflicts
git push