What is "origin" in Git?
2022-07-15
Question When I run: git push origin branchname What exactly is origin and why do I have to type it before the branch name? Answer origin is an alias on your system for a particular remote repository. It's not actually a property of that repository. By doing git push origin branchname you're saying to push to the origin repository. There's no requirement to name the remote repository origin: in fact the same repository could have a different alias for another developer.…
Why does git say "Pull is not possible because you have unmerged files"?
2022-07-15
Question When I try to pull in my project directory in the terminal, I see the following error: harsukh@harsukh-desktop:~/Sites/branch1$ git pull origin master U app/config/app.php U app/config/database.php U app/routes.php Pull is not possible because you have unmerged files. Please, fix them up in the work tree, and then use 'git add/rm <file>' as appropriate to mark resolution, or use 'git commit -a'. Why does git say "Pull is not possible because you have unmerged files"…
How to get just one file from another branch
2022-07-13
Question I have a main branch with a file called app.js. I made changes to this file on an experiment branch. I want to apply only the changes made to app.js from experiment onto the main branch. Answer git checkout main # first get back to main git checkout experiment -- app.js # then copy the version of app.js # from branch "experiment" See also Undo working copy modifications of one file in Git.…
How do I push a new local branch to a remote Git repository and track it too?
2022-07-12
Question How do I: Create a local branch from another branch (via git branch or git checkout -b). Push the local branch to the remote repository (i.e. publish), but make it trackable so that git pull and git push will work. Answer In Git 1.7.0 and later, you can checkout a new branch: git checkout -b <branch> Edit files, add and commit. Then push with the -u (short for --set-upstream) option:…
Clean up a fork and restart it from the upstream
2022-07-11
Question I have forked a repository, then I made some changes and it looks like I've messed up everything. I wish to start it again from scratch, using the current upstream/master as the base for my work. Should I rebase my repository or delete it at all? Answer The simplest solution would be (using 'upstream' as the remote name referencing the original repo forked): git remote add upstream /url/to/original/repo git fetch upstream git checkout master git reset --hard upstream/master git push origin master --force (Similar to this GitHub page, section "…
How to exit a 'git status' list in a terminal?
2022-07-11
Question How can I exit a terminal listing mode generated by the git status command? Answer I have to guess here, but git is probably running its output into your $PAGER program, likely less or more. In either case, typing q should get you out.
Merge, update, and pull Git branches without using checkouts
2022-07-11
Question I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: git merge origin/branchB However, I would also like to keep a local copy of branch B, as I may occasionally check out the branch without first merging with my branch A. For this, I would do: git checkout branchB git pull git checkout branchA Is there a way to do the above in one command, and without having to switch branch back and forth?…