Getting Started:
Set a Git username and email address:
git config --global user.name "your name"
git config --global user.email "[email protected]"
Verify that the changes were made correctly:
git config --list
-
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 status
displays 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.ext
to commit each individual file orgit add -A
this 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.git
this will add in the location of your repo. - Run
git push -u origin master
orgit push -u origin main
this 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.ext
orgit add -A
this 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 push
this 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 - run
git commit --amend --signoff
this will help signoff the previous commit and thengit push --force-with-lease origin master
orgit push --force-with-lease origin main
orgit push --force-with-lease
to update master or main
- Run
git add -A
- Run
git commit -m "commit message here"
this will commit your changes making it ready to be push. - Run
git push
this will send your changes to your remote repo.
Getting started:
-
Initialise: To start using git-flow inside an existing git repository run
git flow init
orgit 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 -A
to add all your new changes - Run
git commit -m "Your commit message"
to commit all the new changes - Run
git push -u origin feature/FEATURENAME
the first time to push all your new changes, and thengit push
after 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 help
and 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 branch
commands’, or various options.
- Run
git fetch
"downloads" any new changes from the remote to your local repository,git fetch --all
will fetch all remotes. - Run
git branch -a
shows all local and remote branches - Run
git branch -r
shows 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 remote
orgit remote show origin
andgit ls-remote
orgit 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 BranchName
i.e git checkoutgit checkout develop
. - If it's a feature branch: Run
git checkout feature/featurename
i.e git checkoutgit checkout feature/task1
.
- Creating a new branch
- Run
git checkout -b branchname
- Run
git branch
to check that it has actually created the branch for you`
- Deleting a branch
- Run
git branch -d branchname
Getting Started
git rebase
allows you to reapply commits on top of another base tip
-
run
git fetch
to "downloads" any new changes from the remote to your local repo -
run
git rebase origin/master
orgit rebase origin/main
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 status
and repeat Step A + B untill all conflicts are resolved.
-
run
git rebase --continue
-
run
git push --force-with-lease
More info
Getting Started: First find out how many commit their are first
- run
git rebase -i HEAD~9
Breaking this command down:
git rebase
— tells our terminal we are running Git with the rebase command-i
— tells git rebase to run in interactive mode (VIM)HEAD~9
— because we want the ability to rebase the last 9 commits (we don’t want to change our initial commit message), the number will depend on the number of commits in your local branch.
- You will get an option in the Vim editor commands of
p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
-
choose your option but for tidying up your commits, i will recommend squashing all commits into 1 and (pick or reword), but choose accordning to need.
-
Save all the changes that you did in the vim editor by running
:wq
to save and exit the vim editor. -
Run
git log
to see everything that we expected did indeed happen.
Insert Mode: The Insert mode lets you insert text in a document. The shortcut is: i
(insert text where the cursor is) or o
(insert text at the beginning of the following line).
Visual Mode: The visual mode permits the user to select the text as you would do with a mouse but using the keyboard instead of the mouse. Useful to copy several lines of text for example. The shortcut is: V
.
Command Mode: When you are in another mod you can use the escape key (sometimes you'll need to hit it twice) to come back to command mod at any time. A command begins with the symbol :
.
Editing
-
In command mode. To start editing the file content, enter:
:i[enter]
-
When you are finished with editing, press the [esc] key to go back to the command mode.
-
To save the file and exit the editor, enter:
:x[enter]
-
In case you want to quit vim without saving the file, enter:
:q![enter]
Extra's: Vim Command Reference
save: :w
save and exit: :wq
exit: :q
force: ! (example :w! :q!)
vertical split: open a document and then type :vsplit /path-to-document/document and this will open the specified document and split the screen so you can see both documents.
copy: y
copy a line: yy
paste: p
cut: d
cut a line: dd
More information here
Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes.
- 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