Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Git questions

Discussion in 'Open Projects' started by fran_m, Oct 9, 2020.

  1. fran_m

    fran_m

    Joined:
    Jul 22, 2020
    Posts:
    40
    Hi,
    If I have the project forked on my local and I want to update it with the main branch, how can I do it? Do I have to delete my forked first and fork again? (I hope there is a better solution)
    Thanks
     
  2. Megatank58

    Megatank58

    Joined:
    Jul 20, 2020
    Posts:
    44
    You just need to click Pull or Fetch Origin button in GitHub desktop
     
  3. myPetWiiUReggie

    myPetWiiUReggie

    Joined:
    Jul 12, 2020
    Posts:
    6
    No, this will pull from your fork's remote on GitHub, not from the main repo.
     
  4. Megatank58

    Megatank58

    Joined:
    Jul 20, 2020
    Posts:
    44
    Have you setted it up correctly? see the contribution guide if you haven't yet.
     
  5. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    No, you don't need to delete the fork.
    This guide goes over it quite well: https://www.tomasbeuzen.com/post/git-fork-branch-pull/
    But I can also explain briefly. I will add numbers in my explanation referring to the paragraphs in that guide.

    The way it works is this:
    Let's say that our repo and branch are
    UnityTechnologies:master
    . We call this the "origin".

    You fork the repo (i.e. just create a copy on Github). Then you open whatever application you use (Github Desktop, SourceTree, Fork, Gitkraken, or just the command line) and you pull your fork's master, say
    fran_m:master
    and you start working there. At this point you could also branch locally, say create a
    fran_m:bugfix
    branch.

    If for any reason, the origin master updates (for instance, we merge another PR into it) it would be great if you take those changes before opening a PR. To do that, you need to add the original repo (not your forked one) as a remote in your desktop application (3).

    Now you can pull from the original
    UnityTechnologies:master
    , and merge the new stuff into your
    fran_m:master
    or
    fran_m:bugfix
    , depending on which one you are using (8).

    Once ready, you open a PR on Github, knowing that the changes you are sending are up to date with the latest on our master, which means it's going to be easier for me to merge them :)
     
    drbier likes this.
  6. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    I do I get assigned to some task in this project?
     
  7. Megatank58

    Megatank58

    Joined:
    Jul 20, 2020
    Posts:
    44
    Sorry, i didn't understood what you said here
     
  8. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
  9. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    Based on rules. At first, You must made request to make changes, then receive rights to made changes of some part of project, made the changes and only after that make new pull request.
    I feel that you skipped many demanded steps
    More detail it described in
    .
     
  10. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    I have opened a pull request from my repo/master to unity repo/main. Now I don't know if the will accept it or not. From then, there are many commits to the unity's repo. On my repo, it show that

    This branch is 1 commit ahead and 13 commits behind unitytecnology's/main

    So what should I do now.
    To update my local and github repo I should

    git pull upstream main (I call upstream unity's one)
    git push origin master (origin is mine)

    But then what about my contribution that is on my local computer and on my github but not in unity's repo, will it be merged or deleted? And if maintainers will not accept the pull request, I will have my contribution (if it's merged) and the main one will not.
     
  11. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    If I right understand the your PR is Created Beach Skybox #128. (You can see by link current status of our PR)
    It's in queue of all requests for changing " UnityTechnologies:main" (It's the main branch of repo for this project)
    As how i see the @cirocontinisio saw your PR (changed label PR). Your PR passed check & ready to merge. I think in nearest time it will be merged.

    It's ok, it means that from last time of sync your copy repo, in repo was merged 13 new commits and you have 1 local commit which yet merged to repo.
    If you want you can pull new commits (13) to your local copy of repo (branch).
    But it is non mandatory (if you do not plan to change the files what was changed)
    It's based on, how you made fork and local branch, which tools you used. For absolutely correct answer at first demanding to see your config (output from the commands below)
    For check can run these command - it doesn't change nothing, but can show your config clear

    git remote -v
    git remote -v show upstream
    get fetch -all
    git branch -vv
    .
    Your contribution in the pull of request. Also i think :) if you didn't use special git commands, It's in your local branch on computer and also may be at your local copy repo on Github.
    Many variants based on your config, but either will be merged, either will left at separed branch (with updated based branch) and you can merge it together later. (By Git commands you can did what you want, by GitHub Desktop variants are more predetermined, but it enough for most standard cases)
    I didn't understand this, and this in your case is not very realistic

    OFFTOP
    o_O
    I finish my first read of Git documentation and :Dready to change status on social networks on
    Do not rebase commits that exist outside your repository and that people may have based work on.
     
    Last edited: Oct 31, 2020
  12. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    That's correct.

    1: you pull the newest changes locally to your computer
    2: you push them to your remote fork

    By doing so, your fork is now aligned with Unity's repo, which should automatically update the PR. On top of that, your contribution will still be there (not lost).
     
  13. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Outputs of commands
    (I followed a tutorial so I have added upstream remote)

    $ git remote -v
    origin https://github.com/HarshNarayanJha/open-project-1.git (fetch)
    origin https://github.com/HarshNarayanJha/open-project-1.git (push)
    upstream https://github.com/UnityTechnologies/open-project-1.git (fetch)
    upstream https://github.com/UnityTechnologies/open-project-1.git (push)

    $ git branch -vv
    * master 8cc83a0 [origin/master] Created Beach Sky box

    $ git remote -v show upstream
    * remote upstream
    Fetch URL: https://github.com/UnityTechnologies/open-project-1.git
    Push URL: https://github.com/UnityTechnologies/open-project-1.git
    HEAD branch: main
    Remote branches:
    Scene-Loading tracked
    art-assets tracked
    main tracked
     
  14. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    Yes, your made standard configuration.
    If I right understood, You didn't make separate branch for your changes (I doesn't see it in output "git branch -vv" or you remove it). In this case @cirocontinisio absolute right "git pull" made merge "your PR" with newest Repo changes (it will be did on your local comp), "git push" sync your local files with your copy Repo (your remote fork).
    P.S>
    If you have separated branch for make changes, it was a little different (you can select make the same merge of your changes with update or make rebase for your branch).
     
  15. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    OK, now for next pull request I shall make a new branch with the name of that branch specific feature or bugfix. Then use git switch to switch the branch and then git add, git commit and then git push, right? After the pull request is merged, I may delete that new branch after pulling and pushing to my master branch.
    And until the pull request is merged, I should left the another branch as it is and update the master branch only?
     
    Last edited: Nov 1, 2020
  16. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    Create of separated (new) branch it's not mandatory for creation new features or bufixes, but recommended.
    • git switch to switch the branch
    • made changes
    • after git add, git commit to made new commit with changes on local Repo on PC
    • after git push to move commit to your local remote Repo (but it's not mandatory)
    • after made Pull Request to 'Upstream" from local Repo on PC or from your local remote Repo
    Your master (main) and "new branch" fully separated therefore you can update main in any time regardless from state of your work in "new branch".

    To simplify work for Integration managers of " UnityTechnologies:main" you can before made Pull Request to 'Upstream":
    • "pull the newest changes locally to your computer" to local branch main
    • rebase your "new branch" to update "local branch main"
    • only after that make the Pull Request to 'Upstream"
    Your "new branch" will be fully not necessary after when your PR was merged in Upstream/main and you pull the new version of it.
     
    cirocontinisio likes this.
  17. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    I didn't use GitHub often before this project (especial for disturbed development), therefore many simple Git tasks & questions wasn't clear to me. And I spent some time to find information & did some tests. I decided "shortly describe" the main tasks & variants of use Git concern to this project.
    I did the most tasks by GitHub Desktop.
    The standard command line Git interface only used for recieve some information which absent in "Desktop interface".
    I made video and put on Youtube (see description for timecode!!!), i think it may be helpful for beginners ("Git&Unity project").
    In any case, I recommend you begin watch from Dapper Dino video.
     
  18. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    In process of rebasing the local branch to new base, I met with a issue - problem of conflict of changes in Scene.unity files from combining branches (not good results of using git rebase/merge and UnityYAMLMerge:): I discussed this issue on Unity forum and get information about way to workaround this issue link to certain post (not to double information), where I detail explain the workaround.
     
  19. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    Ah yes, that's also my workaround when there's a conflict with scenes: rename your local one, pull in the new one, and then do a manual copy-paste of the object you know you want to preserve.
    It's tedious, but it's the only way.
     
  20. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    It's very strange that "Unity Inc" didn't make the tools which help to right menage the process of merging Unity scenes?
     
  21. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    Eh, it's not easy.

    Yesterday I merged two commits that were touching the same scene, but different objects. They merged without a hitch.

    But let's say I make a commit in which I delete an object in a scene, and you make one where you change the values of a component of that object.
    What do you expect to happen if you merge these two?

    Another example. In my commit, I move a UI object from being child n.1 of a certain panel to child n. 7.
    You unparent it and move it to a different panel, child n.3.
    What do you expect to happen here?
     
  22. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    The Help tools :) which will help to work with these non simple situations, which automate that you now doing manually " rename your local one, pull in the new one, and then do a manual copy-paste of the object", e.g.:
    1. You set in git the UnityEditor as "Merge Tool" with some option
    2. When git find a conflict merge, will open UnityEditor in special mode by example with two Inspector window and you can quickly select what will be left/replaced in LOCAL from BASE (It's hard) but automate part of your work "rename your local one, pull in the new one" (it's not difficult) But the deciding what to do with that left to human
     
    cirocontinisio likes this.
  23. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hmm, it's an interesting concept but I think you would soon find many cases that the machine can't interpret. But a scene comparer would be an interesting tool to make... maybe it can be created with having the two scenes loaded at the same time.
     
  24. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    I have a problem, there was a branch called "Scene-Loading", and i have it in my local repo. But it is not now on the Unity's repo. What should I do?

    And there are also new branches like Inventory, how do pull them.
    As i understand, to pull updates to a branch,

    git checkout "branch-name"
    git pull upstream "branch-name"
    git push origin "branch-name"

    but i do i checkout if that branch does not exist in my local repo?
     
  25. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    Have you seen this StackOverflow question/answer about checking out remote branches? The git fetch should help you get all the new branches, then use the checkout -b flag to start using the branch you want to use locally.
     
  26. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    It's merged with main branch and now it's the part of the code of the main branch.
    If you doesn't need to have this branch separated and in the old state - you can delete this branch locally (and on origin also).
    Now if you what to receive the new updates to the "code of Scene-Loading", you must use ("git pull" and etc.) of the main branch.

    git checkout -b "branch-name"

    @shuttle127 also right, but more clear here:
    https://stackoverflow.com/a/1519032/10951191
     
    Last edited: Dec 7, 2020
  27. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Asking to stay on the safe side, will

    git checkout -b localization
    git push origin localization

    work, as these new branch do not show in

    git branch

    output. And to confirm, branch names are case sensitive?

    And also a question,
    SCENARIO 1:
    I'm on the main branch, I use

    git pull upstream art-assets
    git push origin art-assets

    SCENARIO 2:
    I'm on the main branch, I use

    git checkout art-assets
    git pull upstream art-assets
    git push origin art-assets

    Which is the "correct" way?
     
    Last edited: Dec 7, 2020
  28. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    I don't know, in my case all work:

    $ git checkout -b localization
    Switched to a new branch 'localization'

    $ git push origin localization
    Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
    remote:
    remote: Create a pull request for 'localization' on GitHub by visiting:
    remote: https://github.com/DSivtsov/open-project-1/pull/new/localization
    remote:
    To https://github.com/DSivtsov/open-project-1.git
    * [new branch] localization -> localization

    $ git branch
    BugFix
    LastChanges
    Scene-Loading
    Test_Scene_Loading
    art-assets
    * localization
    main
    I can only give link to stackoverflow
    And I recommend before doing "git push origin" make some testing/changes locally (git pull and so on). I don't see any sense to make git push origin immediately after create new branch, because "the idea of git push origin " is "to make second copy of your save ("commit")".
     
    Last edited: Dec 7, 2020
  29. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    This is creating a new local (on your computer) branch called localization that pulls from the localization branch on the GitHub server. This will work if your fork is up-to-date. Check out this git-checkout documentation.

    git branch: Lists what branches you have in your local repository, regardless of what is on the remote repository. When you don't see a branch name in the results of this command, it means you have not checked out that branch from the remote repository and do not have a local copy. The branch name with a * in front of it is the branch git thinks you are currently working on, and what will be checked when you do things like git status.

    In general, adhering to case sensitivity rules/conventions makes sense, so refer to the project's conventions document.

    You can do either, it depends on if you want to start working on the art-assets branch (SCENARIO 2) or not (SCENARIO 1).

    The checkout worked because you didn't already have the localization branch checked out locally, and the corresponding push worked because you did not make any change to worry about merging. All that happened was you synced the localization branch from GitHub onto your computer and then pushed it so you also have a copy in your own GitHub project. EDIT: Noticed you mentioned this in your latest edit, apologies for the repeat.

    Few other git documentation links:
     
    Last edited: Dec 7, 2020
  30. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    For newbie - who begin now work with OpenProject (make fetch & first clone of repo).
    Near two month early, when you cloned project by any git GUI it finished till 1-3 minutes. Now if you try to clone by any GUI you can see some freezing without any results in your local directory.
    It is related to the current repository size of this project (include different branches). Now, I recommend to clone repo by terminal commands:
    - You can run Git terminal by Git Bash which install with most Git GUI (in Windows it commonly at "C:\Program Files\Git)
    - Going to folder where you want to place local copy of repo (don't forget Bash use the Unix style folder & commands)
    - The next command create the local copy of repository (branch main only) from your own fork of the Main Repository and put it into subfolder OpenProject in current directory
    $ git clone https://github.com/<Your GitHub account name>/open-project-1.git OpenProject
    Note. In subfolder OpenProject will be put folder .git & other the root folder of Unit project.
    - After you run this command you can see the process of download (near 9000 object with ~ "summary size near 530MB" with GitHub speed near 30KiB/s). It can be near 2-5 hours.
     
    Last edited: Dec 10, 2020
  31. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Yes, the project it now getting very big. Around 600~700 MB on my laptop (that's including those git binary files)
     
  32. canchen_unity

    canchen_unity

    Joined:
    Mar 13, 2018
    Posts:
    12
    Last edited: Dec 17, 2020
  33. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    To load Pull Request from github

    1.To fetch a remote PR into your local repo:

    git fetch origin pull/<ID>/head:<BRANCHNAME>
    where <ID> is the pull request id and BRANCHNAME is the name of the new branch that you want to create.
    Note. The new branch - BRANCHNAME will based on active branch, which was checkout before you run this command

    2. Once you have created the branch, then simply:

    git checkout BRANCHNAME
     
    Last edited: Dec 17, 2020
  34. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    What mean "based on", will it add to the contents of it, so we have to checkout to a new branch created from the branch for which the pull is?
     
  35. DSivtsov

    DSivtsov

    Joined:
    Feb 20, 2019
    Posts:
    150
    GitLoadPR.JPG
    As you can see (git log --oneline --graph), I before run "git fetch origin" made checkout main (local), which was have last commit f1f9ad9 Relocated stray assets.
    So the PR "Making GameSceneSO more reliable #265" (it content) in my case was added to separate branch dotsquid based on state the project, after commit f1f9ad9 - it was combined with files with content which was in main branch after I get commit from upstream (git pull upstream main), when the last commit was f1f9ad9.
    You can put the interested you PR to the top of any branch - more logical on top of main.
    The Branch is the frozen state of files in the particular time of project life.
    By checkout you decide
    to what time you want to travel in past ( :) or feature if you have own branch with new modifications).

    OFFTOP>
    I have own local branch with specific for me fix (related to support joystick in current version of project & to support the right connection to Unity Services, may be it because I'm use Windows 7, because @cirocontinisio didn't find the same problem at other participants), which I use when made "full test" of last state of project
     
    Last edited: Dec 18, 2020
  36. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Now I have ran into another problem.
    My repository it 42 commits behind and was 24 a few days ago, when I missed to fetch for 2 days. And when the third day, I tried to fetch it failed at 300MBs. I have a daily limit of 1GB. So in the morning, when my internet speed is the greatest. I tried the fetch, it went over 1000MBs and then I had to stop it. I thing it is over 1.5GBs.

    So, my question is, how could I really update my local repo, I can't download so much in one day. I also tried stopping it via CTRL+Z and resuming next day using fg command, but it eventually failed.

    Please help me as the commits are growing everyday and I will be in a dilemma.

    Thanks @DSivtsov, @shuttle127.
     
  37. shuttle127

    shuttle127

    Joined:
    Oct 1, 2020
    Posts:
    183
    Unfortunately there aren't really any legitimate ways to bypass your daily data limit.

    Your best bet might be to stash any local changes you have and then just fork a brand new copy of the code base over the next few days, then make sure you fetch every day to keep the downloads limited in size. If that doesn't work, apparently there is a shallow clone option as well.

    Another idea might be to check out this SO answer about using the --depth=1 flag when you're trying to update your local repo, although I don't think the project uses submodules?

    One last ditch option is to have a friend download your fork and put it on a USB stick for you to then copy to your own computer, although not sure how big it'll need to be or if something like that is feasible for you.
     
    Harsh-NJ and cirocontinisio like this.
  38. cirocontinisio

    cirocontinisio

    Unity Technologies

    Joined:
    Jun 20, 2016
    Posts:
    884
    Thanks for the help, @shuttle127.
    Sorry Harsh, unfortunately the project is growing and now that we have all the scenes in place, it's full of heavy lightmaps, and then the audio files. And it's considered a small project by modern standards!!
     
  39. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    About Recloning, wouldn't it take again those 2GB which I have currently (2GB it project folder, 5GB is .git folder).

    I think --depth=1 helped me but how are sizes calculated, I mean what are percentages for? This is what I get for
    git pull upstream main
    Screenshot_20210630-072702_Termux.jpg
    and with --depth=1 option
    Screenshot_20210630-072446_Termux.jpg

    I need to calculate exact sizes beforehand as I don't want to waste internet data daily.
    Thanks.
     
  40. jsteave

    jsteave

    Joined:
    Mar 13, 2022
    Posts:
    4
    Hi! I have a question about how git pull works and its relationship with the selected branch. If I'm working on a branch other than master, do I necessarily need to do a "git checkout master" before doing the "git pull"? What is the effect of not checking out to the master beforehand?
     
    Last edited: Jul 20, 2022
  41. Harsh-NJ

    Harsh-NJ

    Joined:
    May 1, 2020
    Posts:
    315
    Whatever branch you are currently in, (check that by git status), git pull will pull into that branch
    and BTW, github has changed. It now uses "main", instead of master.

    If you want to pull into main/master branch, checkout to that branch, and run git pull