http://rogerdudler.github.io/git-guide/index.fr.html
"C:\Program Files\Git\git-cmd.exe" --cd-to-home
"C:\Program Files\Git\git-bash.exe"
git pull master
create branch gh-1234
git checkout -b gh-1234
git status
git add src/dir/myfile.py
git commit -a -m 'gh-1234: my comment'
git commit -m 'gh-1234: my comment'
git push --set origin origin/gh-1234
git push origin origin/gh-1234
git checkout master
git status
git stash save gh-XXXXXX
git stash list
git stash show stash@{0}
git stash apply stash@{0}
git stash drop stash@{0}
git log master --oneline
git log master
git log master --pretty=format:"%h - %an, %ar : %s"
git log master --since="2024-08-01"
git log master --since=1.month
git log master --since=1.day
git log master --grep=myname --pretty=format:"%h - %an, %ar : %s"
git log master --grep=gh-1234 --since=30.day
git log master --since=1.month --pretty=format:"%h - %an, %ar : %s"
git log master --grep=gh-1234 --since=30.day
git log -p 1bdb2b2b12c6260f23a8978e563163539960781e
git show --pretty=oneline --name-only --abbrev-commit ^2423a1d4 c142d5b7
git checkout mybranch
git pull
git status
git fetch origin master
git merge origin/master
git push
git status
git checkout master
git pull
git status
git fetch origin mybranch
git merge origin/mybranch
git push
git status
configure winmerge in
C:\Users\<my account>\.gitconfig
git difftool 2423a1d4 c142d5b7
git difftool 2423a1d4:src/myfile.py c142d5b7:src/myfile.py
git branch -a
git branch --contains a4668a08
git difftool a4668a08:src/myfile.py c142d5b7:src/myfile.py
git merge --abort
git.exe clone --progress -v "[email protected]:team/myproject" "C:\projects\myproject"
git checkout <sha1 commit value>
(useful when the branch has been overwritten)
git checkout mybranch
git fetch
git reset --hard origin/mybranch
git pull
let's imagine my current branch is mybranch I want to rename it to gh-1234
git checkout mybranch
git pull
git branch -m gh-1234
--non-- git push
git push origin gh-1234
git push --set-upstream origin gh-1234
git difftool 085c4586dc93f30e538238850
git reset --hard HEAD
git reset --hard origin/master
git reset --hard origin/another-branch
git pull
git status
git log
git reset --hard
(-f
is force
, -d
is remove directories
)
git clean -fd
gitk <filename>
exemple:
gitk mydirectory/myfile.py
git fetch origin
git checkout YOUR_SHA_HERE
ex: git checkout 44cdf6a8095a58f7d6770f7eba1a320a08dbb223
$ git branch --all --merged origin/Y X
$ git gc
$ git fetch --all
$ git reset --hard origin/master
$ git log --graph --decorate
Delete the local branch:
$ git branch -d <branchname>
$ git gc
Remove a remote branch from the server:
$ git push origin --delete {the_remote_branch}
Find all local branches
$ git branch --sort=-committerdate -v
Then
For all <branchname> in [old branches(already closed/on master)]:
$ git branch -d <branchname>
$ git gc
If another dev has pushed to my branch, and I want to retrieve their modifications while I have files in progress:
https://cscheng.info/2017/01/26/git-tip-autostash-with-git-pull-rebase.html
This command:
- stashes the files in progress
- retrieves the commits pushed to the branch (by other devs)
- unstashes the stashed files
$ git pull --rebase --autostash
$ git checkout mybranch
$ git pull
$ gut status
$ git fetch origin master
$ git merge origin/master
$ git pull
$ git status
$ git diff mybranch..master > ../mybranch.patch
$ git checkout master
$ git pull
$ git checkout -b gh-1234
$ git status
$ git apply --3way --ignore-space-change --ignore-whitespace /projects/mybranch.patch
$ git commit
$ git push
/!\ works only if no branch has been merged into this branch (neither master)
Squash last commits of a specifc branch into a single commit.
$ git checkout <branch_name>
$ git pull
$ git status
(replace 3 by the number of commits to squash)
$ git reset --soft HEAD~3
$ git commit -m "my commit message"
$ git push origin <branch_name> --force
Example:
$ git reset --soft HEAD~3
$ git commit -m "feat(gh-1234): my new great feature"
$ git push origin gh-1234 --force
Reintegrate the latest changes from master into my branch without using merge
$ git checkout master
$ git pull
$ git checkout <branch_name>
$ git pull --rebase origin master
$ git push --force-with-lease
$ git checkout master
$ git pull
$ git checkout <branch_name>
$ git pull --rebase origin master
example if there are conflicts:
git pull --rebase origin master
From gitlab.priv.mydomain.com:team/project
* branch master -> FETCH_HEAD
error: could not apply ce26679... feat(gh-1234): my commit message
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply ce26679... feat(gh-1234): my commit message
Auto-merging config/myfile.yaml
CONFLICT (content): Merge conflict in config/myfile.yaml
resolve the merge conflicts, then
$ git rebase --continue
$ git push --force-with-lease
- Open the git window
- Left-click the first commit (the oldest in time) of my branch to select it
- Right-click and choose "interactive rebase" in the popup menu
- Left-click on the bottom-most commit in the list to select it
- Click the "Squash" button
- Edit the commit message
- Click on the icon on the left that looks like 2 small circles
- Click the "Start Rebasing" button
- In the git window, click on the newly generated commit (to select it)
- Right-click to open the popup and click "Push All up to Here..."
- DO NOT CLICK THE "Push" BUTTON!!!
- Click on the down arrow of the "Push" button to display the drop-down menu
- Click "Force Push"
- (a dialog box appears) Confirm by clicking the "Force Push" button
$ git archive -o myproject.zip HEAD