0

I'm a little lost with git, It's the first I use git with other people.

What I want to do is bring the changes that were made in a branch to the branch in which I am working, let's say that when I execute git branch --all what I see is this:

  master
* c
  remotes/origin/HEAD -> origin/master
  remotes/origin/a
  remotes/origin/master
  remotes/origin/c

So, I'm working on the branch c, and I have a friend who made ​​some changes in the branch a, how can I bring his changes to my branch?

The other thing I do not quite understand is how I can work on my own branch, let's suppose I fixed something in the file blah.html.erb, and I want to do a commit and upload it to my own branch, would it be ok to do the following?

git remote add blah.html.erb origin/c
git commit -m "Some changes"
git push origin origin/c

Greetings.

Patricio Sard
  • 2,092
  • 3
  • 22
  • 52
  • Possible duplicate of [Git: getting changes from another branch](http://stackoverflow.com/questions/3124601/git-getting-changes-from-another-branch) – Michael Freidgeim Jan 05 '17 at 01:39

1 Answers1

1

In order to have access to your friend's branch, first you need to fetch them from the remote repository to your local repository with:

git fetch --all

This pulls any branches from the remote repository that don't exist locally and adds them to your repository. Once you've done this, all you have to do is merge his branch into your branch. Assuming you're on your branch (if not just run git checkout c), just run

git merge a

And accept the merge commit that pops up. As far as, "The other thing I do not quite understand is how I can work on my own branch", I think you're misunderstanding some very basic fundamentals of git, and I would highly recommend that you read through the docs to give yourself critical knowledge. Basically though, the idea with git is that you have a local repository, that has a set of data at any given time, and potentially any number of remote repositories that also contain a set of data that may differ from yours depending on when you last synced your local repo with any remote repos.

You should only run git remote add xxxx once; when you want to add a remote repository (xxxx) for future usage. Your local repository already knows it exists (see <your project root>/.git/config), so you don't need to run that again. What you need to do is:

  1. Add a new file to your local index: git add blah.h
  2. Commit that file to your local repository: git commit -m "some changes"
  3. Push your updated branch to the remote repository: git push origin c

Does this make sense? If not, you really, really need to do some more reading on the absolute fundamentals of git. You've made a very good decision to start using git, but it sounds like you have some more digging to do before you're able to use it effectively.

Byte Lab
  • 1,576
  • 2
  • 17
  • 42