Getting Started:
-
Optional: You can use echo to create a new file via the command line
echo "# test" >> README.md -
Initialising git: To start using git inside a new repository that hasn't been initialise with git before, run
git init -
Committing your work: once your ready to push it to the repo
- Run
git statusdisplays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. - Run
git commit filename.extto commit each individual file orgit add -Athis will add all your different file changes. - Run
git commit -m "commit message here"this will commit your changes making it ready to be push. - Run
git remote add origin https://github.com/Usernamme.test.gitthis will add in the location of your repo. - Run
git push -u origin masterthis will send your changes from your local machine to your remote repo, you specify in the step before.
- Additional pushes: once you've made the first push you don't need to add the remote origin again, so your process will be
- Run
git commit filename.extorgit add -Athis will add all your different file changes. - Run
git commit -m "commit message here"this will commit your changes making it ready to be push. - Run
git pushthis will send your changes to your remote repo.
- run
git show- for a single commit will shows the log message and textual difference - run
git show --stat- will show you the changes made - run
git log --stat- will show you the commits message and files changes made - run
git log- will show you the commits message - run
git reset --soft HEAD~1- this will undo your last commit
Getting started:
-
Initialise: To start using git-flow inside an existing git repository run
git flow initorgit flow init -fd. You'll have to answer a few questions regarding the naming conventions for your branches. It's recommended to use the default values. -
Starting a new feature: To start developing a new feature run
git flow feature start NewFeature. This action creates a new feature branch based on 'develop' and switches to it. -
Once a new feature has been created you can then start making changes in the code.
- Run
git add -Ato add all your new changes - Run
git commit -m "Your commit message"to commit all the new changes - Run
git push -u origin feature/FEATURENAMEthe first time to push all your new changes, and thengit pushafter the first initial push. - You can then make a pull request to have your new feature merged with the develop branch.
-
Finishing a new feature: Once your new feature has been merge into the develop branch, to finish the development of the feature run
git flow feature finish FEATURENAME. This action will remove the feature branch and switches back to the develop branch. -
For help run
git flow helpand you should recieve the following instruction.
usage: git flow <subcommand> Available subcommands are:
init Initialize a new git repo with support for the branching model.
usage: git flow init [-h] [-d] [-f] - Setup a git repository for git flow usage. Can also be used to start a git repository.
-h, --help Show this help
--showcommands Show git commands while executing them
-d, --[no]defaults Use default branch naming conventions
-f, --[no]force Force setting of gitflow branches, even if already configured
--Use config file location
--local use repository config file
--global use global config file
--system use system config file
--file ... use given config file
feature Manage your feature branches.
bugfix Manage your bugfix branches.
release Manage your release branches.
hotfix Manage your hotfix branches.
support Manage your support branches.
version Shows version information.
config Manage your git-flow configuration.
log Show log deviating from base branch.
Try 'git flow <subcommand> help' for help or git flow init --help.
Getting started:
- The easiest way is just to use the
git branchcommands’, or various options.
- Run
git fetch"downloads" any new changes from the remote to your local repository,git fetch --allwill fetch all remotes. - Run
git branch -ashows all local and remote branches - Run
git branch -rshows only remote branches. - There’s also another way to figure out what branches are on your remote by actually using the remote related commands,
git remoteorgit remote show originandgit ls-remoteorgit ls-remote --heads origin.
The ls-remote command returns the SHA1 hash of the latest commit for that reference, so it is quite easy to parse out and get to the exact commit you need if you’re doing some scripting. The --heads option lists only branch names since the command can list tags too.
- Once you know the name of the branch it’s quite simple to check them out.
- Run
git checkout BranchNamei.e git checkoutgit checkout develop. - If it's a feature branch: Run
git checkout feature/featurenamei.e git checkoutgit checkout feature/task1.
Getting Started
git rebase allows you to reapply commits on top of another base tip
-
run
git fetchto "downloads" any new changes from the remote to your local repo -
run
git rebase origin/master
If there are any conflicts, you will see a message similar to the below.
Step A - run git status to see where or which files contains conflicts.
Step B - Access the files and resolved the conflicts and then run git add filename.ext
- run
git statusand repeat Step A + B untill all conflicts are resolved.
-
run
git rebase --contiune -
run
git push --force-with-lease
More info
- Fetch and check out the branch for this merge request
git fetch origin
git checkout -b branchname origin/branchname
-
Review the changes locally
-
Merge the branch and fix any conflicts that come up
git fetch origin
git checkout origin/develop
git merge --no-ff branchname
Step 4. Push the result of the merge to the repository
git push origin develop
