The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other I really need a good tutorial on Git branches.

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #158967

    Today, I attempted to create a new branch for a project.

    I then attempted to pull ONLY that branch onto a remote server. What happened from there is me messing a lot of stuff up… FAST.

    I managed to somehow replace my master branch with the new branch in another directory on the remote server, so I tried to fix it and delete the branch, only to find out I had not just deleted the branch but deleted the actual files on my local machine. I was able to retrieve it by finding some copy Git saves… I just got in big trouble really fast.

    What’s amazing is… I looked at my terminal history and was shocked that I did that much damage with the simple commands I ran. Crazy.

    Suffice it to say… I REALLY don’t understand how to branch properly. Can someone please give me some material to educate my ignorant ass?


    Well, what you might have missed is that, when you switch branches, git changes your “working tree” to match what that branch should look like. It literally changes all of the files in your project. They are not gone. When you switch back to master, for example, the files will be changed back to what they were when you last committed to master.

    To address your specific problem of pulling a branch to your remote server, you need to [create and] switch to that branch on the remote first, then pull it from your local machine. Then your remote can work on it, merge it, or switch back to master and ignore the branch if desired.

    Have you looked at the git branch examples?


    Unless you deleted the repo, you should be able to revert it. But I couldn’t be sure how, without knowing what you did and what state the tree was in.

    If I understand your first post correctly, you wanted to:

    • create a new branch locally

    • work on it and commit

    • save the new branch to your remote (i.e., not merge with the remote master)


    …create and checkout new branch

    $ git checkout -b myNewBranch

    …work on new branch

    $ git add ./my/new/files.etc
    $ git commit -am 'my new files'

    …push to myNewBranch on remote (will be created if it doesn’t exist yet)

    $ git push <remote-name> myNewBranch

    I’m too have one question on git pull requests.

    Here is my situation – I made changes on for-example-branch and send pull requests to remote repository, my pull request don’t merge (because it was outdated), author of repository made changes to update my pull request – does it updated my for-example-branch on my PC or shoud I make git pull to recieve the changes?

    Thanks for reply.


    You won’t get the changes unless you pull them.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Other’ is closed to new topics and replies.