Rename a Local and Remote Git Branch Combine multiple commits into one Check branch contains commit Pull force Show commit Upload changes from branch Remove commit Show config AutoCRLF Task list between tags Move commit to another branch
Follow the steps below to rename a Local and Remote Git Branch:
- Start by switching to the local branch which you want to rename:
git checkout <old_name>
- Rename the local branch by typing:
git branch -m <new_name>
At this point, you have renamed the local branch. If you’ve already pushed the <old_name> branch to the remote repository, perform the next steps to rename the remote branch.
- Push the <new_name> local branch and reset the upstream branch:
git push origin -u <new_name>
- Delete the <old_name> remote branch:
git push origin --delete <old_name>
That’s it. You have successfully renamed the local and remote Git branch.
Suppose that you want to merge the last 3 commits into a single commit. To do that, you should run git rebase in interactive mode (-i) providing the last commit to set the ones that come after it. Here, HEAD is the alias of the very last commit.
git rebase -i HEAD~3
After the first step, the editor window will show up offering you to input the command for each commit.
All you need to do is replacing pick with squash, starting from the second line. Then, save the file.
One more editor window will show up to change the resulting commit message. Here, you can find all your commit messages and change them according to your exact needs.
If you have already pushed your commits, then you should force push them using the git push command with — force flag
$ git branch --contains <commit-id>
git checkout master
git branch new-branch-to-save-current-commits
git fetch --all
git reset --hard origin/mastergit show <commit-id>git pull origin developgit pull --rebase origin developRemove last commit
git reset --hard HEAD^Remove 2 last commits
git reset --hard HEAD~2if reset --hard doesn't work
git gc
git reset
git reset --hard <target_branch>shows all inherited values from: system, global and local
git config -lWindows uses both a carriage-return character and a linefeed character for newlines in its files, whereas macOS and Linux systems use only the linefeed character. This is a subtle but incredibly annoying fact of cross-platform work; many editors on Windows silently replace existing LF-style line endings with CRLF, or insert both line-ending characters when the user hits the enter key.
Git can handle this by auto-converting CRLF line endings into LF when you add a file to the index,
and vice versa when it checks out code onto your filesystem.
You can turn on this functionality with the core.autocrlf setting.
If you’re on a Windows machine, set it to true this converts LF endings into CRLF when you check out code:
$ git config --global core.autocrlf trueadd, commit checkout
--------------> Git database -------------->
(CRLF -> LF) (LF) (LF -> CRLF)If you’re on a Linux or macOS system that uses LF line endings, then you don’t want Git to automatically convert them when you check out files; however, if a file with CRLF endings accidentally gets introduced, then you may want Git to fix it. You can tell Git to convert CRLF to LF on commit but not the other way around by setting core.autocrlf to input:
$ git config --global core.autocrlf inputadd, commit checkout
--------------> Git database -------------->
(CRLF -> LF) (LF) (no convertation)If you’re a Windows programmer doing a Windows-only project, then you can turn off this functionality, recording the carriage returns in the repository by setting the config value to false:
$ git config --global core.autocrlf false add, commit checkout
--------------> Git database -------------->
(no convertation) (CRLF and/or LF) (no convertation)If you're working on Windows with shell scripts, you can add .gitattributes file like this:
docker-compose.yml text eol=lf
Dockerfile eol=lf
*.sh text eol=lfecho 'Please enter start tag'
read startTag
echo 'Please enter end tag'
read endTag
git log --oneline $startTag..$endTag | grep -o MYTAG-[0-9]* | sort --unique
echo 'Task were showed'use commit hash
git cherry-pick 707e522 get changes without commiting
git cherry-pick -n 707e522