How do you refresh the remotes in Magit? - emacs

Magit is really nice, but I have yet to figure out how to create a remote branch from it, or how to refresh the remote branches it knows without deleting the remote and adding it back in.
Currently I go to github, add a branch, then go into magit, delete the remote, and then add it back. Is there a better way?

Refreshing a remote branch should be done with a git fetch.
With Magit (documentation):
Typing f f will run git fetch.
It will prompt for the name of the remote to update if there is no default one.
Typing f o will always prompt for the remote.
Typing F F will run git pull.
When you don’t have a default branch configured to be pulled into the current one, you will be asked for it.
As Rémi commented, f a would fetch all remotes.
Actually, as akaihola comments in 2018:
If you type F, you get the "pull" menu.
Then:
p pulls from the push default (see b M-p), and
e from elsewhere (e.g. another remote branch).
Creating a remote branch should be pushing a local branch to a remote:
Magit will run git push when you type P P.
If you give a prefix argument to P P, you will be prompted for the repository to push to.
When no default remote repository has been configured yet for the current branch, you will be prompted as well.
Typing P P will only push the current branch to the remote.
In other words, it will run git push <remote> <branch>.
The branch will be created in the remote if it doesn’t exist already.
The local branch will be configured so that it pulls from the new remote branch.
If you give a double prefix argument to P P, you will be prompted in addition for the target branch to push to.
In other words, it will run git push <remote> <branch>:<target>.

Related

In Eclipse git, how to change the duplicate the local branch created on one source to the new source

In Eclipse git,
I have created my local branch from source "S1" branch and pushed the changes. But now different source "S2" is created and I am asked to send merge request on the "S2" branch for same code changes.
I am new to Egit , can Any one tell me how can i duplicate my local branch from S1 source to S2 source?
From Git Repositories view, checkout branch S1 then open history, select the last commit from S1 (or whatever commit you'd like to start S2 from), and then right-click on the commit > Create branch....
Note that Git and EGit don't force you to have a branch named S2 to push to a remote named S2. You can simply work on S1, commit on S1, and in the Push... dialog, set S2 as target ref. That should create the remote S2 branch with last commit included.
In general, it's important to keep in mind that a git push action always has a src local ref (commit or branch) and a target remote ref (branch), and that those don't need to have the same name. Even if src and target refs in git push commands are (too) often ignored and made implicit, keeping that in mind and using "disambiguised" git commands often allows to better understand navigation. EGit push wizards is smart enough to make it explicit and pre-set to good default (you'll usually won't need to change), so you get best of both worlds.

how to clone all branches and not just master in Atom Text Editor

I have a repository on Github which consist of two branches. I am trying to use Git-Plus:Clone in Atom to try to clone all repositories. However, all my attempts have failed and only the master branch gets cloned. I have looked this problem up on SE but could not find a way to do it. Can someone kindly help me figure this out. Thanks in advance !
However, all my attempts have failed and only the master branch gets cloned.
This behavior is not unique to Atom. It's the normal git clone behavior.
All branches are cloned, but git clone will only automatically make a local branch for master or whatever the default branch for the repository is. The rest remain as "remote tracking branches", local copies of the remote. They're on your disk, but they're effectively read-only. Git does this to avoid flooding your clone with possibly a bazillion irrelevant local branches, should the project you're cloning have a lot of branches.
For example, if your remote has master, foo, and bar. You will wind up with origin/master, origin/foo, origin/bar, and master. origin/... are all remote tracking branches. They remember the state of the remote repository the last time you looked at it (with a git clone, or fetch or pull).
master is a local branch of origin/master for you to work on. If you want to work on another branch, make a local version of it. For example, git checkout -b origin/foo foo would create a local foo for you to work on (or however you do it in Atom).
See also this answer.
In Atom, install Git Plus package in Preferences, then toggle command palette (on mac it's cmd+shift+p) and type checkout, select "Git Plus: Checkout Remote" from the suggested list of items in the drop-down menu.
Then you just need to select the target repo and branch you wish to check out and the remote branch will become local and you will be able to work on it and switch between different branches.

git multiple pull requests

I'm a git noob in a shared environment, but have used it for personal projects fine.
I'm trying to contribute to a project, so I did this:
Forked the project.
Made code changes.
Committed code changes to my local branch.
Pushed changes to my fork
Did a pull request.
That worked great. PR is still pending, but I had some other ideas.
So, I created a new local branch.
Made code changes
Committed code changes to local branch
Pushed changes to my forked copy
Did a PR
The code changes from my previous edits are obviously in place with this PR. I do not want that, since they haven't been committed to the main branch.
Likewise, I want to make additional changes and push them specifically without containing the code from my previous work.
How is this accomplished?
Since you already started a second pull request, you'll have to forego best practices:
rebase your local <PR-2-branch> to start of PR-1 (say 8 commits ago). use -i to start an interactive session.
git rebase -i HEAD~8
In the editor window that opens up, hit i and mark commits from PR-1 (5 commits) to be drop or d and pick or p commits from PR-2 (3 commits)
d 113456 <message>
d 223456 <message>
d 333456 <message>
d 443456 <message>
d 553456 <message>
p 663456 <message>
p 773456 <message>
p 883456 <message>
Press Esc > w > q to exit the editor and to proceed with the rebase.
The branch now contains only commits within the scope of current PR.
Update the remote branch with --force
git push origin <PR-2-branch> --force

Deleting a commit in github

Is it possible to undo one or two faulty commits I have made to Github. I'm not very good at coding either so if there's a way to do it without coding, that would be great.
Thank you very much
You can do this via doing the following command in your local workspace:
git reset --merge <hash>
Where <hash> is the commit prior to the commits that you want to revert.
The above command is enough if you haven't pushed to GitHub. If you have pushed to GitHub, you then run the following to force an update of the remote branch:
git push --force origin <branch>
(Note: This is assuming that your remote is named origin, but rename as appropriate.)
Note that this re-writes history on the remote branch, and is not recommended if other developers are using the same branch. If you know who the developers are, you can communicate with them to delete their local copies of the modified branch and ask them to run git fetch to get a new copy of the branch.

Local branch not created when pulling new remote branches (Git)

I am using EGit 2.1.0 in eclipse juno.
A user X has created and pushed a branch FeatureBranch. Next user Y pulls from master. Now in the Remote Tracking the FeatureBranch is visible on user Y's machine. Now user Y want to join the work done on FeatureBranch. But the FeatureBranch is not automatically available as a local branch. So user Y first needs to create a local branch from the remote FeatureBranch (else all commits will end up being seen as detached heads).
Why does user Y have to manually create a local branch from the remote branch before being able to commmit/push on it?
That's just how git works. Remote branches are read-only. If you want to automate the git checkout --track or whatever it is you want to do, you could certainly script it.