Git
GIT commands
Set remote repository URL
git remote add origin http://git-server/repository.git
Change remote repository URL
git remote set-url origin http://git-server/repository.git
Checkout remote branch as local
If -B is given,
git checkout -b release/202109-rel-ocp4 origin/release/202109-rel-ocp4
Checkout and push branch to remote under different name
git push
git push origin refs/heads/release/xy:feature/ab
Create local branch from current branch and push remotely
git checkout -b release/r1
git push -u origin release/r1
### Create local branch from remote
git checkout -b develop origin/develop
Rebase – add all commits from a branch to the current branch
-f -history was change - force required -i -interactive –rebase-merges -u -set-upstream
git rebase -i --rebase-merges develop
git push -u origin release/r1 -f
### Rewrite last commit
git add *
git commit --amend -m "last commit comment"
git push -u origin feature/2 --force-with-lease
Show what was changed in working directory
git diff --name-only
### Show what was added and will be commited
git diff --cached
Git adds (stages) all changes
git add -A
git adds (stages) new files and modifications, without deletions (on the current directory and its subdirectories).
git add .
git adds (stages) modifications and deletions, without new files
git add -u
git log - get commits
This Git command displays the commit history from a specific commit (1.6.0) up to the latest commit (HEAD), excluding merge commits. The output is formatted using the –oneline flag, which shows each commit on a single line, along with its hash value and commit message.
The output is then piped into the grep command with the regular expression [A-Z]+.-[0-9]+.*, which matches lines containing a sequence of capital letters followed by a hyphen and numbers, optionally followed by any other text. This format may match issue identifiers in project management, such as “JIRA-1234” or “GH-5678”.
git log 1.6.0..HEAD --no-merges --oneline | grep -E '[A-Z]+.-[0-9]+.*'