Table of contents

Contents

Practical Git Guide

Solutions to 90% of your daily git challenges

Solutions to 90% of your daily git challenges

#N1
Development team

I want to clone a project and start going through the code.

I want to clone a project and start going through the code.

  • Get the repo URL/link
  • Open your terminal
  • Navigate to the location in the terminal where you want your project to be cloned
  • Enter the command git clone URL

The repo URL can be found inside the repo.

Image 3

Github repo link example Image 4

#N2
Development team

I have cloned the repo. But I am not able to see the proper code!!!

I have cloned the repo. But I am not able to see the proper code!!!

By default the main/master branch is active. Ask which branch has the relevant code

  • Navigate inside the cloned folder cd repo<-name>
  • Enter the command git switch <branch-name>

Image 5

Note: The checkout command can also be used to switch the branch. git checkout <branch-name>

#N3
Development team

Someone has made a few changes in the code and asked me to pull those changes. What should I do?

Someone has made a few changes in the code and asked me to pull those changes. What should I do?

  • Pull the changes git pull

Image 6

#N4
Development team

I have modified the code and added changes. How do I commit my changes?

I have modified the code and added changes. How do I commit my changes?

First stage all the files and then commit your changes. You can create multiple commits.

  • Stage the files git add *
  • Commit the changes git commit -m 'Your commit message'

Image 7

#N5
Development team

What if I want only some of my files added & pushed instead of all changes?

What if I want only some of my files added & pushed instead of all changes?

You can add files by mentioning the file/files with relative or full path. You can add files one by one or multiple files at a time using the commands

  • Add single file git add <file-path>
  • Add multiple files git add <file1-path> <file2-path>

Image 8

Similarly, to unstage a file use the command git reset

#N6
Development team

I have modified/formatted some code while going through it. Now I want the code to be back to the state as it was.

I have modified/formatted some code while going through it. Now I want the code to be back to the state as it was.

  • To reset all the changes git reset --hard
  • To reset a single file git checkout HEAD -- <file-path>

Image 9

#N7
Development team

I have committed my changes. How can I undo my change?

I have committed my changes. How can I undo my change?

You can undo the commit by resetting the HEAD. If you just want to undo the commit but let the changes be present then use the soft attribute else if you do want the commit along with the changes then use the hard attribute

git reset --soft HEAD~1 (undo with changes preserved) 
git reset --hard HEAD~1 (undo with changes removed) 

#N8
Development team

I have made some changes to the branch. Also, I wanted to pull the new changes. But it is not working.

I have made some changes to the branch. Also, I wanted to pull the new changes. But it is not working.

The command git pull may not work if the changes are done by someone else to the same files which you have also modified.

  • Stash the changes git stash save <name of the change> -u
  • Pull the changes now git pull
  • Retrieve the changes git stash apply <n>

where n is the stash number. To get the list of stashes git stash list

Image 10

Note: You can stash multiple changes and bring them back as and when you like to

#N9
Development team

After applying the stash, I am getting a lot of conflicts in the code.

After applying the stash, I am getting a lot of conflicts in the code.

If there are changes in the code on the region of the stashed code, it is expected to get conflicts. You will have to manually resolve all the conflicts. (Do it carefully)

Image 11

Below is the view of the VSCode, which helps in easily resolving the conflicts.

Image 12

#N10
Development team

I have made some code changes. But I want to commit to a new separate branch.

I have made some code changes. But I want to commit to a new separate branch.

You can create a separate branch out of the current branch and commit it. This works both if you have already made changes or are yet to start making changes.

  • Create a new branch git switch -c <my-branch-name>
  • Stage all the changes git add *
  • Commit the changes git commit -m "<some commit message>"

To switch between the branches use the command git checkout <original-branch-name>

Image 13

Alternatively, checkout command can also be used to create the branch. git checkout -b <my-branch-name>

Note: my-branch-name is your local branch and not available for anyone else unless you push it

#N11
Development team

I just committed but forgot to add a few files to the commit. Is there a way to update the same commit with some modifications?

I just committed but forgot to add a few files to the commit. Is there a way to update the same commit with some modifications?

Yes. You can update the commit by amending your changes.

  • To add files git add <file-name> <file-name> ...
  • To update the commit git commit --amend --no-edit

To update with new commit message git commit --amend -m 'My new commit message' (This command can also be used to update previous commit message without any code modifications)

--no-edit is used to avoid the prompt to edit commit message. If you wanna modify commit message as well, during commit update, then do not include -m along with your commit message

Image 14

Note: The amend updates the previous commit without creating a new one on top of the previous. (in reality, Git discards the previous commit and replaces it with a new commit)

#N12
Development team

I am asked to raise a Pull Request (PR). What am I supposed to do?

I am asked to raise a Pull Request (PR). What am I supposed to do?

You can follow the same steps as given in the previous question. Once done you will push the code and raise a PR. It's that simple. Here we assume you are on the 'develop' branch and raising PR to the 'main' branch.

  • Create a new branch git switch -c <my-branch-name>
  • Stage all the changes git add *
  • Commit the changes git commit -m "<some commit message>"
  • Push the changes git push (as the branch is not present on the remote, it will show the command to use)
  • Enter git push --set-upstream origin <my-branch-name>

Image 15

The URL to raise the PR will be automatically available as shown above. Use the link and open it in the browser.

Image 16

Now select the base branch to which you want to raise a PR and click on 'Create a PR'

#N13
Development team

I do not want a branch anymore. How can I delete the branch?

I do not want a branch anymore. How can I delete the branch?

To delete a branch locally, check out a different branch than the one you want to delete. Here we will delete the branch named 'develop'

  • Switch to other branch git checkout <other-branch>
  • Delete branch git branch -d <branch-name>

To delete the branch from remote as well

  • Delete remote branch git push -d <remote> <branch-name>

Image 17

Note: If -d does not allow to delete a branch, use the -D . Example: git branch -D <branch-name>

#N14
Development team

I want to rename my local and remote branches. How can I do it?

I want to rename my local and remote branches. How can I do it?

To rename a branch, checkout to the branch and rename it.

  • Check out other branch git checkout <your-branch-name>
  • Rename your branch git branch -m <new-branch-name>
  • Push to remote git push <remote> :<your-branch> <new-branch-name>
  • Set upstream git push <remote> -u <new-branch-name>

<remote> is usually origin

Image 18

#N15
Development team

I have made some changes to the code on the branch on which all of the developers are working. How can I publish my changes?

I have made some changes to the code on the branch on which all of the developers are working. How can I publish my changes?

To move the changes from your local machine to remote (called origin), follow the below steps in your terminal

  • Stage the files git add *
  • Commit the changes git commit -m "<some commit message>"
  • Push the changes git push

Image 19

#N16
Development team

I created a commit and also pushed it. Is it possible to update that commit now?

I created a commit and also pushed it. Is it possible to update that commit now?

Yes. You can update the commit even after it is pushed. Everything will follow as mentioned in the previous question, but you will have to force push.

  • git add <file-name> <file-name> ...
  • git commit --amend --no-edit or git commit --amend
  • git push -f or git push --force

Image 20

Note: You need to be very careful while pushing forcefully, as it may eliminate other commits if someone has done in between. Make sure you are working on the branch and no one else is simultaneously working on the same or branching out from the branch at your commit.

#N17
Development team

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. I am stuck!!!

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. I am stuck!!!

The rejection could be because the remote branch might be ahead of the local branch. Different techniques can be used here to achieve sync.

  • Pull the changes git pull
  • Continue with the merge commit created automatically
  • git push

Image 21

If there are conflicts, then resolve them manually to proceed ahead as shown below.

#N18
Development team

I followed the above steps but got conflicts after git pull.

I followed the above steps but got conflicts after git pull.

If there are code changes on the same region from multiple commits, conflicts will occur. You need to resolve all the conflicts and proceed.

  • Resolve all the conflicts
  • Stage files git add <file-path>
  • Continue the merge git merge --continue
  • Push the changes git push

Image 22

Note: If something goes wrong, in any of the above steps, then there is nothing to panic about. Just run git merge --abort and redo the steps.

#N19
Development team

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. Can I pull the new changes without merging the commit (Rebase)?

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. Can I pull the new changes without merging the commit (Rebase)?

Yes. You can pull the changes without a merge. This is called Rebase. I know you have heard it a lot. It is very simple though.

  • Pull with rebase git pull --rebase
  • Push the changes git push

Image 23

If you get conflicts, then solve all the conflicts. Then

  • git rebase --continue
  • Resolve all conflicts
  • Push the changes git push

Image 24

Note: If something goes wrong, in any of the above steps, then there is nothing to panic about. Just run git rebase --abort and redo the steps.

#N20
Development team

I have raised a PR (Pull Request). But it is showing conflicts.

I have raised a PR (Pull Request). But it is showing conflicts.

Image 26

PR will show conflicts if the new changes added to the source branch are conflicting with your changes or your branch is lagging.

There are 2 main approaches to solve this.

  • Merge approach
  • Rebase approach

Follow any one of the approaches. Don't try both of them. Assuming that your branch is develop and the source branch is main

Merge approach

  • Checkout to main branch git checkout main
  • Pull changes git pull
  • Checkout to your branch git checkout develop
  • Merge the changes git merge main
  • Resolve all the conflicts and add to staging git add <files>
  • If conflicts are present git merge --continue
  • Push the changes git push

Image 27

Rebase approach

  • Checkout to main branch git checkout main
  • Pull changes git pull
  • Checkout to your branch git checkout develop
  • Rebase the branch git rebase main
  • Resolve all the conflicts and add to staging git add <files>
  • Run git rebase --continue after resolving the conflicts
  • Push the changes git push -f

Image 28

Note: You may have to run git rebase --continue multiple times if there are multiple conflicts on your multiple commits.

#N21
Development team

I have many commits. How can I transform them into a single commit (squash)?

I have many commits. How can I transform them into a single commit (squash)?

Converting multiple commits into one is known as Squashing. We will achieve this by rebasing with the help of the interactive feature of the editor (VSCode). This will be both easier and simple.

  • Run git rebase -i HEAD~<n> (where n refers to the number of commits to squash)
  • Mark all the commits as 'Squash' except the oldest one
  • Click on 'Start rebase'
  • Enter the commit message

Image 29

Image 30

Image 31

Note: If you had already pushed the commits, then you will have to use the command git push -f to reflect squash on the remote branch as well.

#N22
Development team

I have many commits. How can I transform them into a single commit (squash) with just commands?

I have many commits. How can I transform them into a single commit (squash) with just commands?

You can use the technique of undoing to achieve this easily.

  • Undo the number of commits you need to squash git reset --soft HEAD~<n>
  • Commit them again git commit -m 'Commit message'

Note: If you had already pushed the commits, then you will have to use the command git push -f to reflect squash on the remote branch as well.

#N23
Development team

I am trying to rebase my branch with the same or another branch. As I have many commits, I am getting a lot of conflicts on every commit to rebase.

I am trying to rebase my branch with the same or another branch. As I have many commits, I am getting a lot of conflicts on every commit to rebase.

  • You can first squash all commits to one commit.
  • Once done, rebase the branch and resolve all conflicts in a single go.

#N24
Development team

I have made changes and committed to a branch. I want to copy the same changes to another branch.

I have made changes and committed to a branch. I want to copy the same changes to another branch.

To copy the changes of a commit from one branch to another, you can use cherry pick. First obtain the commit id of the commit, which you want to copy.

  • Checkout the branch git checkout <destination-branch>
  • Cherry-pick the commit git cherry-pick <commit-id>

Image 33

#N25
Development team

I have tried to cherry-pick. But I am getting conflicts.

I have tried to cherry-pick as shown in 24. But I am getting conflicts.

If you get any conflicts, resolve the conflicts first. Once all the conflicts are resolved, they continue the cherry-pick.

  • Add resolved files to stage git add <file-paths>
  • Continue cherry-pick git cherry-pick --continue

Image 34

Note: If something goes wrong in between, reset the process by using the command git cherry-pick --abort (You can start the process again)

#N26
Development team

I have multiple commits which I want to move to a different branch.

I have multiple commits which I want to move to a different branch.

To copy a range of commits from one branch to another, you can note down the older commit id from history and the newer commit id.

  • Checkout the branch git checkout <destination-branch>
  • Cherry pick the commit git cherry-pick <old-commit-id>..<new-commit-id>

Image 35

#N27
Development team

I have pushed my changes and got it merged. I want to revert it immediately.

I have pushed my changes and got it merged. I want to revert it immediately.

Revert creates a reverse commit where the changes made will reverse and is created as a new commit. To revert a particular commit first, obtain its commit id.

  • Revert the commit git revert <commit-id>
  • Push the commit git push

Image 36

#N28
Development team

How do I reset the code of my branch to the code of a different branch?

How do I reset the code of my branch to the code of a different branch?

When resetting a branch to a different branch, the codebase on your branch will become the same as the other branch. To achieve this, you can use the 'reset' command.

  • Checkout to the branch git checkout <your-branch-bame>
  • Reset with the branch name git reset --hard <source-branch>

In this case, 'your-branch-name' will match the codebase of 'source-branch'

Image 37

#N29
Development team

I want to delete/undo the previous commit from my branch which I have already pushed. I am not looking for a revert. I just want to delete it

I want to delete/undo the previous commit from my branch which I have already pushed. I am not looking for a revert. I just want to delete it.

Revert will reverse the changes creating a new commit. If you want to remove the previous commit, then you can undo and force push the branch.

  • Reset by undoing git reset --hard HEAD~<n> (n is the number of commits to undo)
  • Push the changes git push -f

Image 39

Note: Force push is needed as the history of the branch is changing in this. If the commit is not pushed then it is not needed.

#C1
Development team

I want to clone a project and start going through the code.

I want to clone a project and start going through the code.

  • Get the repo URL/link
  • Open your terminal
  • Navigate to the location in the terminal where you want your project to be cloned
  • Enter the command git clone URL

The repo URL can be found inside the repo.

Image 3

Github repo link example Image 4

#C2
Development team

I have cloned the repo. But I am not able to see the proper code!!!

I have cloned the repo. But I am not able to see the proper code!!!

By default the main/master branch is active. Ask which branch has the relevant code

  • Navigate inside the cloned folder cd repo<-name>
  • Enter the command git switch <branch-name>

Image 5

Note: The checkout command can also be used to switch the branch. git checkout <branch-name>

#C3
Development team

Someone has made a few changes in the code and asked me to pull those changes. What should I do?

Someone has made a few changes in the code and asked me to pull those changes. What should I do?

  • Pull the changes git pull

Image 6

#C4
Development team

I have modified the code and added changes. How do I commit my changes?

I have modified the code and added changes. How do I commit my changes?

First stage all the files and then commit your changes. You can create multiple commits.

  • Stage the files git add *
  • Commit the changes git commit -m 'Your commit message'

Image 7

#C5
Development team

What if I want only some of my files added & pushed instead of all changes?

What if I want only some of my files added & pushed instead of all changes?

You can add files by mentioning the file/files with relative or full path. You can add files one by one or multiple files at a time using the commands

  • Add single file git add <file-path>
  • Add multiple files git add <file1-path> <file2-path>

Image 8

Similarly, to unstage a file use the command git reset

#C6
Development team

I have modified/formatted some code while going through it. Now I want the code to be back to the state as it was.

I have modified/formatted some code while going through it. Now I want the code to be back to the state as it was.

  • To reset all the changes git reset --hard
  • To reset a single file git checkout HEAD -- <file-path>

Image 9

#C7
Development team

I have committed my changes. How can I undo my change?

I have committed my changes. How can I undo my change?

You can undo the commit by resetting the HEAD. If you just want to undo the commit but let the changes be present then use the soft attribute else if you do want the commit along with the changes then use the hard attribute

git reset --soft HEAD~1 (undo with changes preserved) 
git reset --hard HEAD~1 (undo with changes removed) 

#C8
Development team

I have made some changes to the branch. Also, I wanted to pull the new changes. But it is not working.

I have made some changes to the branch. Also, I wanted to pull the new changes. But it is not working.

The command git pull may not work if the changes are done by someone else to the same files which you have also modified.

  • Stash the changes git stash save <name of the change> -u
  • Pull the changes now git pull
  • Retrieve the changes git stash apply <n>

where n is the stash number. To get the list of stashes git stash list

Image 10

Note: You can stash multiple changes and bring them back as and when you like to

#C9
Development team

After applying the stash, I am getting a lot of conflicts in the code.

After applying the stash, I am getting a lot of conflicts in the code.

If there are changes in the code on the region of the stashed code, it is expected to get conflicts. You will have to manually resolve all the conflicts. (Do it carefully)

Image 11

Below is the view of the VSCode, which helps in easily resolving the conflicts.

Image 12

#C10
Development team

I have made some code changes. But I want to commit to a new separate branch.

I have made some code changes. But I want to commit to a new separate branch.

You can create a separate branch out of the current branch and commit it. This works both if you have already made changes or are yet to start making changes.

  • Create a new branch git switch -c <my-branch-name>
  • Stage all the changes git add *
  • Commit the changes git commit -m "<some commit message>"

To switch between the branches use the command git checkout <original-branch-name>

Image 13

Alternatively, checkout command can also be used to create the branch. git checkout -b <my-branch-name>

Note: my-branch-name is your local branch and not available for anyone else unless you push it

#C11
Development team

I just committed but forgot to add a few files to the commit. Is there a way to update the same commit with some modifications?

I just committed but forgot to add a few files to the commit. Is there a way to update the same commit with some modifications?

Yes. You can update the commit by amending your changes.

  • To add files git add <file-name> <file-name> ...
  • To update the commit git commit --amend --no-edit

To update with new commit message git commit --amend -m 'My new commit message' (This command can also be used to update previous commit message without any code modifications)

--no-edit is used to avoid the prompt to edit commit message. If you wanna modify commit message as well, during commit update, then do not include -m along with your commit message

Image 14

Note: The amend updates the previous commit without creating a new one on top of the previous. (in reality, Git discards the previous commit and replaces it with a new commit)

#C12
Development team

I am asked to raise a Pull Request (PR). What am I supposed to do?

I am asked to raise a Pull Request (PR). What am I supposed to do?

You can follow the same steps as given in the previous question. Once done you will push the code and raise a PR. It's that simple. Here we assume you are on the 'develop' branch and raising PR to the 'main' branch.

  • Create a new branch git switch -c <my-branch-name>
  • Stage all the changes git add *
  • Commit the changes git commit -m "<some commit message>"
  • Push the changes git push (as the branch is not present on the remote, it will show the command to use)
  • Enter git push --set-upstream origin <my-branch-name>

Image 15

The URL to raise the PR will be automatically available as shown above. Use the link and open it in the browser.

Image 16

Now select the base branch to which you want to raise a PR and click on 'Create a PR'

#C13
Development team

I do not want a branch anymore. How can I delete the branch?

I do not want a branch anymore. How can I delete the branch?

To delete a branch locally, check out a different branch than the one you want to delete. Here we will delete the branch named 'develop'

  • Switch to other branch git checkout <other-branch>
  • Delete branch git branch -d <branch-name>

To delete the branch from remote as well

  • Delete remote branch git push -d <remote> <branch-name>

Image 17

Note: If -d does not allow to delete a branch, use the -D . Example: git branch -D <branch-name>

#C14
Development team

I want to rename my local and remote branches. How can I do it?

I want to rename my local and remote branches. How can I do it?

To rename a branch, checkout to the branch and rename it.

  • Check out other branch git checkout <your-branch-name>
  • Rename your branch git branch -m <new-branch-name>
  • Push to remote git push <remote> :<your-branch> <new-branch-name>
  • Set upstream git push <remote> -u <new-branch-name>

<remote> is usually origin

Image 18

#C15
Development team

I have made some changes to the code on the branch on which all of the developers are working. How can I publish my changes?

I have made some changes to the code on the branch on which all of the developers are working. How can I publish my changes?

To move the changes from your local machine to remote (called origin), follow the below steps in your terminal

  • Stage the files git add *
  • Commit the changes git commit -m "<some commit message>"
  • Push the changes git push

Image 19

#C16
Development team

I created a commit and also pushed it. Is it possible to update that commit now?

I created a commit and also pushed it. Is it possible to update that commit now?

Yes. You can update the commit even after it is pushed. Everything will follow as mentioned in the previous question, but you will have to force push.

  • git add <file-name> <file-name> ...
  • git commit --amend --no-edit or git commit --amend
  • git push -f or git push --force

Image 20

Note: You need to be very careful while pushing forcefully, as it may eliminate other commits if someone has done in between. Make sure you are working on the branch and no one else is simultaneously working on the same or branching out from the branch at your commit.

#C17
Development team

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. I am stuck!!!

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. I am stuck!!!

The rejection could be because the remote branch might be ahead of the local branch. Different techniques can be used here to achieve sync.

  • Pull the changes git pull
  • Continue with the merge commit created automatically
  • git push

Image 21

If there are conflicts, then resolve them manually to proceed ahead as shown below.

#C18
Development team

I followed the above steps but got conflicts after git pull.

I followed the above steps but got conflicts after git pull.

If there are code changes on the same region from multiple commits, conflicts will occur. You need to resolve all the conflicts and proceed.

  • Resolve all the conflicts
  • Stage files git add <file-path>
  • Continue the merge git merge --continue
  • Push the changes git push

Image 22

Note: If something goes wrong, in any of the above steps, then there is nothing to panic about. Just run git merge --abort and redo the steps.

#C19
Development team

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. Can I pull the new changes without merging the commit (Rebase)?

I have created single/multiple commits. When I am trying to push my changes, getting a rejected message. Can I pull the new changes without merging the commit (Rebase)?

Yes. You can pull the changes without a merge. This is called Rebase. I know you have heard it a lot. It is very simple though.

  • Pull with rebase git pull --rebase
  • Push the changes git push

Image 23

If you get conflicts, then solve all the conflicts. Then

  • git rebase --continue
  • Resolve all conflicts
  • Push the changes git push

Image 24

Note: If something goes wrong, in any of the above steps, then there is nothing to panic about. Just run git rebase --abort and redo the steps.

#C20
Development team

I have raised a PR (Pull Request). But it is showing conflicts.

I have raised a PR (Pull Request). But it is showing conflicts.

Image 26

PR will show conflicts if the new changes added to the source branch are conflicting with your changes or your branch is lagging.

There are 2 main approaches to solve this.

  • Merge approach
  • Rebase approach

Follow any one of the approaches. Don't try both of them. Assuming that your branch is develop and the source branch is main

Merge approach

  • Checkout to main branch git checkout main
  • Pull changes git pull
  • Checkout to your branch git checkout develop
  • Merge the changes git merge main
  • Resolve all the conflicts and add to staging git add <files>
  • If conflicts are present git merge --continue
  • Push the changes git push

Image 27

Rebase approach

  • Checkout to main branch git checkout main
  • Pull changes git pull
  • Checkout to your branch git checkout develop
  • Rebase the branch git rebase main
  • Resolve all the conflicts and add to staging git add <files>
  • Run git rebase --continue after resolving the conflicts
  • Push the changes git push -f

Image 28

Note: You may have to run git rebase --continue multiple times if there are multiple conflicts on your multiple commits.

#C21
Development team

I have many commits. How can I transform them into a single commit (squash)?

I have many commits. How can I transform them into a single commit (squash)?

Converting multiple commits into one is known as Squashing. We will achieve this by rebasing with the help of the interactive feature of the editor (VSCode). This will be both easier and simple.

  • Run git rebase -i HEAD~<n> (where n refers to the number of commits to squash)
  • Mark all the commits as 'Squash' except the oldest one
  • Click on 'Start rebase'
  • Enter the commit message

Image 29

Image 30

Image 31

Note: If you had already pushed the commits, then you will have to use the command git push -f to reflect squash on the remote branch as well.

#C22
Development team

I have many commits. How can I transform them into a single commit (squash) with just commands?

I have many commits. How can I transform them into a single commit (squash) with just commands?

You can use the technique of undoing to achieve this easily.

  • Undo the number of commits you need to squash git reset --soft HEAD~<n>
  • Commit them again git commit -m 'Commit message'

Note: If you had already pushed the commits, then you will have to use the command git push -f to reflect squash on the remote branch as well.

#C23
Development team

I am trying to rebase my branch with the same or another branch. As I have many commits, I am getting a lot of conflicts on every commit to rebase.

I am trying to rebase my branch with the same or another branch. As I have many commits, I am getting a lot of conflicts on every commit to rebase.

  • You can first squash all commits to one commit.
  • Once done, rebase the branch and resolve all conflicts in a single go.

#C24
Development team

I have made changes and committed to a branch. I want to copy the same changes to another branch.

I have made changes and committed to a branch. I want to copy the same changes to another branch.

To copy the changes of a commit from one branch to another, you can use cherry pick. First obtain the commit id of the commit, which you want to copy.

  • Checkout the branch git checkout <destination-branch>
  • Cherry-pick the commit git cherry-pick <commit-id>

Image 33

#C25
Development team

I have tried to cherry-pick. But I am getting conflicts.

I have tried to cherry-pick as shown in 24. But I am getting conflicts.

If you get any conflicts, resolve the conflicts first. Once all the conflicts are resolved, they continue the cherry-pick.

  • Add resolved files to stage git add <file-paths>
  • Continue cherry-pick git cherry-pick --continue

Image 34

Note: If something goes wrong in between, reset the process by using the command git cherry-pick --abort (You can start the process again)

#C26
Development team

I have multiple commits which I want to move to a different branch.

I have multiple commits which I want to move to a different branch.

To copy a range of commits from one branch to another, you can note down the older commit id from history and the newer commit id.

  • Checkout the branch git checkout <destination-branch>
  • Cherry pick the commit git cherry-pick <old-commit-id>..<new-commit-id>

Image 35

#C27
Development team

I have pushed my changes and got it merged. I want to revert it immediately.

I have pushed my changes and got it merged. I want to revert it immediately.

Revert creates a reverse commit where the changes made will reverse and is created as a new commit. To revert a particular commit first, obtain its commit id.

  • Revert the commit git revert <commit-id>
  • Push the commit git push

Image 36

#C28
Development team

How do I reset the code of my branch to the code of a different branch?

How do I reset the code of my branch to the code of a different branch?

When resetting a branch to a different branch, the codebase on your branch will become the same as the other branch. To achieve this, you can use the 'reset' command.

  • Checkout to the branch git checkout <your-branch-bame>
  • Reset with the branch name git reset --hard <source-branch>

In this case, 'your-branch-name' will match the codebase of 'source-branch'

Image 37

#C29
Development team

I want to delete/undo the previous commit from my branch which I have already pushed. I am not looking for a revert. I just want to delete it

I want to delete/undo the previous commit from my branch which I have already pushed. I am not looking for a revert. I just want to delete it.

Revert will reverse the changes creating a new commit. If you want to remove the previous commit, then you can undo and force push the branch.

  • Reset by undoing git reset --hard HEAD~<n> (n is the number of commits to undo)
  • Push the changes git push -f

Image 39

Note: Force push is needed as the history of the branch is changing in this. If the commit is not pushed then it is not needed.

README.md

A utility-first CSS framework for rapidly building custom user interfaces.

build
passing
downloads
8.7M

Documentation


For full documentation, visit tailwindcss.com

Community


For help, discussion about best practices, or any other conversation that would benefit from being searchable:
Discuss Tailwind CSS on GitHub
For casual chit-chat with others using the framework:
Join the Tailwind CSS Discord Server

Contributing


If you're interested in contributing to Tailwind CSS, please read our contributing docs before submitting a pull request.

© 2020 GitHub, Inc.,