This is a simple git cheat sheet that talks through the commands and the workflow
To install git on Linux use the following command:
$ sudo 'packageManagerName' install git
Example:
$ sudo apt install git
On windows or bash, you can use git-bash. Download here
So now you have git installed, you want to turn this folder into a git repo (Short for repository). To do this, we run the initialize command like this:
$ git init
If successful, the current folder has been turned into a git repo. This means we can start issuing git commands to it
To check our git version, we should simply use the following command
$ git version
To check the status of the current/parent folders, type:
$ git status
Once we have created our git repo locally, if we want to make this folder public, we must create a repo on a git server like github or gitlab. Once you have done that, copy the URL at the top and past it in here:
$ git remote add 'nameOfGitServer' 'url'.git
We can then see the added remote by typing
$ git remote -v
Before we commit anything, we must add them to the staging area, where they are ready to be committed. To do this, we will use the following command:
$ git add 'filenames (Seperated by a space)'
To add all of the files, simply type the following:
$ git add . -A
Once you have ran one of these commands, you are ready to commit your files.
To commit our files, we just can just run the commit command
$ git commit
This will put us in a nano editor though, where we will type our message to say what changes have been made. To do this all through the command line, use:
$ git commit -m "My Message That Goes With The Commit"
To push our files to a remote repo, like the ones we added earlier, we can use the git push command, like this:
$ git push 'Remote Name' 'Branch'
Example:
$ git push github master
To create a new branch, you must use the branch command like this:
$ git branch 'nameOfBranch'
To see all of the branches, run this command:
$ git branch
To switch branches, use the checkout
command like this:
$ git checkout 'nameOfBrach'
This means that any change we make in any editor goes towards that branch. To make and switch to a branch at one time, go like this:
$ git checkout -b 'nameOfBrach'
When we create a branch, we copy over the current branches files, but just rename the branch.
To merge 2 branches, we will use the merge
command, like this:
$ git merge 'nameOfBranch'
This will start a do a new commit with the merge.
You can use an open source project to organize your git workflow. Here is how to use it.
To initialize a new repo with the basic branch structure, use:
git flow init [-d]
This will then interactively prompt you with some questions on which branches you would like to use as development and production branches, and how you would like your prefixes be named. You may simply press Return on any of those questions to accept the (sane) default suggestions.
The -d
flag will accept all defaults.
To list/start/finish feature branches, use:
$ git flow feature
$ git flow feature start <name> [<base>]
$ git flow feature finish <name>
For feature branches, the arg must be a commit on develop.
To push/pull a feature branch to the remote repository, use:
$ git flow feature publish <name>
$ git flow feature pull <remote> <name>
To list/start/finish release branches, use:
$ git flow release
$ git flow release start <release> [<base>]
$ git flow release finish <release>
For release branches, the <base> arg
must be a commit on develop.
To list/start/finish hotfix branches, use:
$ git flow hotfix
$ git flow hotfix start <release> [<base>]
$ git flow hotfix finish <release>
For hotfix branches, the <base> arg
must be a commit on master.
To list/start support branches, use:
$ git flow support
$ git flow support start <release> <base>
For support branches, the <base> arg
must be a commit on master.
Taken from the README.md file on github