GIt help - acehand/anaAr GitHub Wiki

Scenario: Show me which branches I have on my local machine
Solution: List branches
Steps:

$ git branch -l #you will notice the branch you are currently on will have a ** next to the name

Scenario: I have some code I want to version/share, but I don't want to commit to master.
Solution: Create a new branch and push it up to remote origin.
Steps:

$ git checkout -b branchname #This creates a new branch and switches to it. It will move your code over to this branch

$ git status #Run to verify you are on a branch, read the first line
"# On branch branchname" ...

$ git add . && git commit -m "bugzid: NNNN - message" #Add the files you wish to commit, and commit them with your usual process

$ git push origin branchname #This pushes the branch up to remote origin

Scenario: I want to add code to someone's branch that is present on remote origin
Solution: checkout the remote branch locally
Steps:

$ git fetch #This will ensure that git knows about the remote branch

$ git checkout --track -b branchname origin/branchname #this creates a local branch named branchname, and then tells it to track the remote origin branch branchname

$ git status #Run to verify you are on a branch, read the first line
"# On branch branchname" ...

now you can run your usual process, git add . && git commit -m "message" etc...

Scenario: I am on a branch, and I want to commit code to master
Solution: checkout master
Steps:
$ git checkout master #switch back to master branch

$ git status #Run to verify you are on a branch, read the first line
"# On branch branchname"
...

$ git add . && git commit -m "message" #do your usual file editing and checkin procedures

Scenario: I am done working on my branch, and I want to pull those commits into master
Solution: merge branch into master
Steps:
$ git status #Run to verify you are on a branch, read the first line
"# On branch branchname"
...

$ git checkout master #switch to master

$ git status #Run to verify you are on master, read the first line
"# On branch master"
...

$ git pull origin master #get the latest changes from remote origin

$ git merge branchname #begins the merge process, one of two things can happen, no merge conflicts, or some merge conflicts

-----------No merge conflicts
If the changes don't conflict, you're done.

$ git push origin master #to push your changes up to remote origin
If someone snuck in a commit while you were doing this just run:
$ git pull
It is important to note that you should never use git pull --rebase when performing a merge
$ git push origin master #to push your changes up to remote origin

-----------Merge conflicts have occured. The usual merge conflict markers will be left in the problematic files showing the conflict.

$ git status #find which files are conflicted

$ vim conflicted_file.php #solve the conflicts in your usual manner

$ git add . #to add all files,
OR
$ git add path/to/files/file.php

$ git commit #Once your done just run commit. Git will know that it’s a merge and generate the appropriate commit message.

aside: You can also run git commit -a, which essentially is the same thing as running git add . && git commit

$ git push origin master #to push your changes up to remote origin
If someone snuck in a commit while you were doing this just run:
$ git pull
It is important to note that you should never use git pull --rebase when performing a merge
$ git push origin master #to push your changes up to remote origin

Scenario: I am on a branch, and there are changes in master I want in my branch
Solution: Merge master into branch
Steps:

$ git status #Run to verify you are on a branch, read the first line
"# On branch branchname"
...

$ git pull origin branchname #get the latest changes

$ git merge master #begins the merge process, one of two things can happen, no merge conflicts, or some merge conflicts

-----------No merge conflicts
If the changes don't conflict, you're done.

$ git push origin branchname #to push your changes up to remote origin
If someone snuck in a commit while you were doing this just run:
$ git pull
It is important to note that you should never use git pull --rebase when performing a merge
$ git push origin branchname #to push your changes up to remote origin

-----------Merge conflicts have occurred. The usual merge conflict markers will be left in the problematic files showing the conflict.

$ git status #find which files are conflicted

$ vim conflicted_file.php #solve the conflicts in the usual manner

$ git add . #to add all files,
OR
$ git add path/to/files/file.php

$ git commit #Once your done just run commit. Git will know that it’s a merge and generate the appropriate commit message.

aside: You can also run git commit -a, which essentially is the same thing as running git add . && git commit

$ git push origin branchname #to push your changes up to remote origin
If someone snuck in a commit while you were doing this just run:
$ git pull
It is important to note that you should never use git pull --rebase when performing a merge
$ git push origin branchname #to push your changes up to remote branch

Scenario: I am done with a branch and I want to remove it from both local and remote origin
Solution: push an empty branch to remote origin, and delete it from local
Steps:

$ git push origin :branchname #this tells git to delete the branch from remote origin. In essence it's pushing an empty branch up to remote origin which will take the place of the old branch, and then will get gc'ed eventually.

$ git branch -l #but the branch is still in my list?

$ git branch -d branchname #this will delete the branch from your local machine

Situation: I made a commit on my computer that I have NOT pushed up to the server yet. I want to continue developing but save this commit for later.
Solution: Create a patch

Steps: $ git format-patch -1 #this will create a file that looks something like this: 0001-dompdf6-updates-to-use-pdflib-8.patch

To merge your patch back into git ..

$ cat 0001-dompdf6-updates-to-use-pdflib-8.patch | git am

⚠️ **GitHub.com Fallback** ⚠️