Checkout a remote git branch
This is from StackFlow:
git fetch origin
git checkout -b test origin/test
or
git fetch
git checkout test
Create pull requests on GitHub
0. Fork an existing repository on GitHub, then on the local machine, clone the forking repository
git clone https://github.com/lammps/lammps.git
Now if you go to lammps/ and do git branch, you will see it is currently at master (of the forked repository).
1. Create an upstream branch for the remote repository, from which we just forked
git remote add upstream url-of-the-remote-repository
For example
git remote add master-upstream url-of-the-remote-repository
2. Update the branch with the latest changes
git fetch upstream
Note that upstream may contain multiple branches.
3. Switch to the branch we want to create the fixes to (maybe already exists, e.g. lammps-icms)
git checkout lammps-icms
4. Merge the corresponding branch of upstream into the target branch
git merge upstream/lammps-icms
5. Create a separate branch from the current branch to start working on
git checkout -b my-fixes
and then create the corresponding branch on github
git push origin my-fixes
6. Work on the branch, make changes then commit
git commit -a
7. Push to the corresponding branch on github
git push origin my-fixes
8. Create a pull request on github
Create and apply patches with git
Instructions for creating and applying a patch using git are given elsewhere in the Internet. I just re-iterate here for my quick reference:
A. Create a patch
1. Clone/pull the source
2. Create a new branch from master and switch to it to work on
git checkout -b bug-fixes
If there is already another remote branch, switch to it (without creating)
git branch branch-name
If a merge master into that branch is needed
git merge master
If we want to create a new branch from branch-name instead of master
git checkout -b bug-fixes branch-name
3. Check how many commits were made
git diff master..HEAD
which means compare the original source code (in master) with the current code in the bug-fixes branch (HEAD).
4. Generate patches (.patch files) each corresponding to a commit
git format-patch -M -B master
If there are many commits, tar them into an archive
tar -cvf single.patch *.patch
B. Apply a patch
1. Check the changes due to the patch
git apply --check file.patch
2. Apply the patch
git am --signoff < file.patch
3. Undo the patch applying
git am --abort
4. Always check the log and status
git log
or
git status
3. If there is one error or two with the applying, use the patch command instead of git apply
patch -p1 < file.patch
4. Still have errors, go to the file and edit the line reported
Alternatively, create a tarball for modified files, untar the tarball in the root of the git repository. Then run git diff and redirect the output into a text file
git diff > patch.diff
To undo the unstaged changes made by the modified source files, use git checkout
git checkout -- .