Reputation: 45
so first I made a repository on github, then put the comands below in the console:
echo "# rotten-tomatoes" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/ejample/file.git
git push -u origin main
and this pushes the project on github.
My partner clones the project with
git clone https://github.com/ejample/file.git
Now what's next? let's see, the project has Side A, Side B, Side C, Side D, he'd work in A and B and I in C and D, everytime we are done with a side we make a push but we also want to upgrade our local projects with the advances the other one is making, what's the best approach to do this? my guess is e.g
Once he cloned the project I start working on it, then when I'm done with side C I put these lines below
git checkout -b rick
git add .
git commit -m "side C completed"
git push origin rick
Then I want my partner to have the new changes in his local project, what should he do? I know he must use git pull
but how? because when I use git pull rick
the output is
fatal: 'rick' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
even though the branch rick exists. What am I doing wrong?
Upvotes: 0
Views: 1619
Reputation: 1862
@matt's answer is I think a bit overcomplicated. Your partner (having cloned), needs just to do:
git checkout rick
git pull
The complicated bit emerges when you both change things - so you are both working on a branch at the same time, rather than handling over:
For reason's like the above, it is often cleaner to use different branches and control when you merge.
Upvotes: 0
Reputation: 536028
You do not pull by branch name alone, but by remote name and branch name.
git pull origin rick
However, your partner cannot pull this branch at all, because pulling is into the current branch, and there is no local branch rick
on your partner's machine. Instead, your partner will just say:
git fetch
Now your partner has a copy of the rick
branch in the remote tracking branch origin/rick
. That remote tracking branch is open to inspection. If there is a need to check out that branch (for example, to test what it does, or to modify it), then:
git checkout rick
This by default will neatly create a local rick
based on origin/rick
. From then on, it will be possible for either of you to
git checkout rick
git pull origin rick
Upvotes: 2