Merge, update, and pull Git branches without using checkouts

The Short Answer As long as you’re doing a fast-forward merge, then you can simply use git fetch <remote> <sourceBranch>:<destinationBranch> Examples: # Merge local branch foo into local branch master, # without having to checkout master first. # Here `.` means to use the local repository as the “remote”: git fetch . foo:master # Merge … Read more

How can I make my local repository available for git-pull?

Five possibilities exist to set up a repository for pull from: local filesystem: git clone /path/to/repo or git clone file://path/to/repo. Least work if you have networked filesystem, but not very efficient use of network. (This is almost exactly solution proposed by Joakim Elofsson) HTTP protocols: git clone http://example.com/repo. You need any web server, and you … Read more

Git push only for bare repositories?

Read the warning carefully. The new default prohibition is only on pushing to the currently checked out branch in a non-bare repository. It is perfectly OK to push to any other branch in a non-bare repository. The reason for this is that the push process has no direct access to the working tree so the … Read more

GitHub – fatal: could not read Username for ‘https://github.com’: No such file or directory

Follow the steps to setup SSH keys here: https://help.github.com/articles/generating-ssh-keys OR git remote add origin https://{username}:{password}@github.com/{username}/project.git Update: If you get “fatal: remote origin already exists.” then you have to use set-url: git remote set-url origin https://{username}:{password}@github.com/{username}/project.git

‘git pull origin mybranch’ leaves local mybranch N commits ahead of origin. Why?

git pull calls git fetch with the appropriate parameters before merging the explicitly fetched heads (or if none the remote branch configured for merge) into the current branch. The syntax: git fetch <repository> <ref> where <ref> is just a branch name with no colon is a ‘one shot’ fetch that doesn’t do a standard fetch … Read more

In what cases could `git pull` be harmful?

Summary By default, git pull creates merge commits which add noise and complexity to the code history. In addition, pull makes it easy to not think about how your changes might be affected by incoming changes. The git pull command is safe so long as it only performs fast-forward merges. If git pull is configured … Read more

git stash and apply

Quick “TL;DR” take-away version, so one can come back later and study more git stash hangs a stash-bag—this is a peculiar form of a merge commit that is not on any branch—on the current HEAD commit. A later git stash apply, when you’re at any commit—probably a different commit—then tries to restore the changes git … Read more

tech